Hello,
I am using a EditorControl for a column in my ultragrid. The type of EditorControl I am using is UltraTextEditor and I added two StateEditorButtons to this control as depicted in the image I provided. The question that I have is that when you click one of the StateEditorButtons; making it checked value 'true', all cells in that column using the EditorControl StateEditorButton become checked as well, is there way to make this work only on the cell you clicked the StateEditorButton on? Please advise.
I attached the image so that you can see my dilemma when check state of the StateEditorButton changes for this column.
Adrian
I think whats happening here is that the grid is using the same copy of the editor for every cell in the column and there isn't anything that will store the individual state for each of the cells. To get around this, you will need an editor for each of the cells, though I think that creating an entirely new control isn't necessary and adds overhead. You could create a new editor in the InitializeRow event, i.e.:
private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e){ if (e.Row.Cells["Col 1"].Editor == null) { EditorWithText editor = new EditorWithText(); editor.ButtonsRight.Add(new StateEditorButton()); e.Row.Cells["Col 1"].Editor = editor; }}
If you do want to set things up at design-time, you might be able to get away with:
private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e){ if (e.Row.Cells["Col 1"].Editor == null) { EditorWithText editor = (EditorWithText)this.ultraTextEditor1.Editor.Clone(null); e.Row.Cells["Col 1"].Editor = editor; }}
-Matt
Hello Matt,
The second option seems to be working really well for me. Thanks alot!
Sorry to bother you with another question. But, I was wonder if changed the DisplayStyle of those StateEditorButtons to RadioButton, is there a way to get them act like true radiobuttons?
No, there is no built-in support to do this. You would have to loop through all the editors to manually sync them since there is no infrastructure in place for the editors to know that they should do this.
Hello Matt
When you say loop them all, do you mean at time you are in the ultraGrid1_InitializeRow? Could you clarify for me please.
Also, I noticed when I used this way
to get my desired result earlier that the ultraTextEditor1_EditorButtonClick no longer works. Is it now impossible to catch an event from these statebuttons with the change you suggested?
Thanks,
Adrian,
You won't be able to trap the EditorButtonClick event of the control because you're now creating a clone of the editor that the control is not aware of. I think a better option is to hook the Click event of each editor and use that to change the state. You'd probably have to use the GetContext method on the button.Editor.ElementBeingEdited to get the UltraGridCell that is associated with the state button too.
As for looping through all cells, I mean that when you detect that the state has changed on a button, at that point you need to loop through all of the other rows to make sure that none of them are checked, assuming that you want these to behave like a radio button.
Ok this clearing it up for some, however, I was looking on the editor for a 'Click' event but there is none. Am I looking in the wrong place?
I do understand how to get the ultragridcell from what you described though. Like this I am assuming.
UltraGridcell aCell = ((UltraGridCell)e.Row.Cells["Col 1"].Editor.ElementBeingEdited.GetContext());
This should help alot. Thanks again for all the help!
Click is on the base EmbeddableButtonBase class, so it will appear on the StateEditorButton too. But now that you mention it, I think that it would be better to hook the AfterEditorButtonCheckStateChanged events since at that point the buttons have been updated.
private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e){ if (e.Row.Cells["Col 1"].Editor == null) { EditorWithText editor = (EditorWithText)this.ultraTextEditor1.Editor.Clone(null); StateEditorButton checkButton = (StateEditorButton)editor.ButtonsRight[0]; checkButton.AfterCheckStateChanged += new EditorButtonEventHandler(checkButton_AfterCheckStateChanged); e.Row.Cells["Col 1"].Editor = editor; }}void checkButton_AfterCheckStateChanged(object sender, EditorButtonEventArgs e){ // Handle the check logic}
Sorry for the late response. Perhaps I am not understanding how to get to the events on the StateEditorButton correctly, so I apologize for being a nuisance, but could you direct me as to how to get to the Click event programmatically. I did research the online documentation available and saw that the editor has events such as, BeforeEditorButtonCheckStateChanged and AfterEditorButtonCheckStateChanged available. Would those be of any use to me?
I misspoke, I meant the Click event on the StateEditorButton. As for the GetContext, you'd likely have to pass in "typeof(UltraGridCell)" as well in order to get the cel.