Hei i have a text editor defined as following
textEditor = new UltraTextEditor();chkBtn = new EditorButton();textEditor.ButtonsRight.Add(chkBtn); textEditor.EditorButtonClick += new EditorButtonEventHandler(chkBtn_click);
I set the control to a column
this.DisplayLayout.Bands[0].Columns[columnName].CellMultiLine= Infragistics.Win.DefaultableBoolean.True;this.DisplayLayout.Bands[0].Columns[columnName].EditorControl= textEditor;this.DisplayLayout.Bands[0].Columns[columnName].EditorControl.Enabled = true;
I want the editor button to do some work on click, the code works fine.
but I loose my editor :( , when i use same code with LoadFromXml
Am i doing something wrong ?
The XML file cannot store an entire object like an editor. The thing to do is create the editor and attach it to the grid in the InitializeLayout event. That way it will get applied to the column every time you load the layout.
By the way, if you are going to create a control at run-time like you are doing here, it's a good idea to add that control to the Form's Controls collection. Otherwise, it will never be disposed and open up a potential memory leak.
I tried attaching the editor control on initialise layout event, still the same problem.Basically we are trying to create a custom control using the ultragrid.
THE CONTROL===========
I am inhereting UltraGrid in my custom control.Then i attach an Editor to the control private void UltraWinGrid7_Initializelayout(object sender, InitializeLayoutEventArgs e) { textEditor = new UltraTextEditor(); chkBtn = new EditorButton(); textEditor.ButtonsRight.Add(chkBtn); textEditor.EditorButtonClick += new EditorButtonEventHandler(chkBtn_click); SetAsEditableTextColumn("LongText"); }
We also have some methods which control can use to set a column style
public void SetAsEditableTextColumn(string columnName) { this.DisplayLayout.Bands[0].Columns[columnName].CellMultiLine = Infragistics.Win.DefaultableBoolean.True; this.DisplayLayout.Bands[0].Columns[columnName].EditorControl = textEditor; this.DisplayLayout.Bands[0].Columns[columnName].EditorControl.Enabled = true; }
{ this.DisplayLayout.Bands[0].Columns[columnName].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.TriStateCheckBox;}
THE FORM========
In a form which use this control The form uses control methids
ultraWinGrid71.DataSource = createDataSource();ultraWinGrid71.SetEditorTextBox(txtBox);ultraWinGrid71.SetAsCheckBoxColumn("bool"); ultraWinGrid71.SetAsEditableTextColumn("LongTexta");this.ultraWinGrid71.DisplayLayout.LoadFromXml(typeof(Form1) + ".xml");
SetEditorTextBox passes reference of a simple textBox to control.The textbox, which we use along with control's EditorControl , :) we open it when EditorButton is clicked.
Now when i comment the line //this.ultraWinGrid71.DisplayLayout.LoadFromXml(typeof(Form1) + ".xml"); it works as expected
But when i use LoadFromXml the grid fails to show the EditorControl ..The other column (SetAsCheckBoxColumn) works fine
Any other hint ,why is it ,not working
Pushpendra
Hi the problem is solved ! On your suggestion i played aruound with "LoadFromXml"strangly it depends on when you set your DataSource , i was trying to add layour before setting teh datasource.But now when i do it after setting the datasource it works fine.
ultraWinGrid71.DataSource = createDataSource();this.ultraWinGrid71.DisplayLayout.LoadFromXml(typeof(Form1) + ".xml");
Seems Datagrid depends on Data to decide how the layout is done (Layout is not dynamic i mean)
Mike Thanks a ton for all suggestion help :)
Does the line of code which sets the EditorContorl on the column get called after you load the layout? If so, then I'm not sure why it's not working. If not, then that is the problem.