Hi,
I have ultragrid with ultraTextEditor using ultraControlContainerEditor1.
I want to capture the ultraTextEditor text as soon as user type in it, in short every key stroke with in the ultraTextEditor.
I tried to do this using ultraGrid1_CellChange event , but it is not triggering at all for any cell I change the value.
Hello Lizzy,
The CellChnage event triggers when the cell exits edit mode and the new value could be obtained when the row that the cell belongs to is updated. If you would like to use the CellChange event and get the value of the cell on every key stroke, what I can suggest you is exiting edit mode on cell change, then updating the row and after that obtaining the new value of the cell and then entering edit mode again. In order to not get the cell texts selected, I recommend you obtaining the selection length from the EditorReselved and then setting the SelectionStart to this index. This would place the caret right at the end of the cell content and the user would be able to edit the cell without having to deselect and placing the caret at the end of the cell.
For example if you would like to place the newly changed text from the UltraTextEditor inside of the UltraGrid in a TextBox using the CellChnaged event the code below could be used to achieve this:
private void UltraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { if (e.Cell.Column.Key.Equals("Text")) { this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode); e.Cell.Row.Update(); textBox1.Text = e.Cell.Value.ToString(); this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode); // obetain the length of the selected text when entering edit mode and then place the carretIndex at the end of it int carretIndex = e.Cell.EditorResolved.SelectionLength; e.Cell.EditorResolved.SelectionStart = carretIndex; } }
I have also created a small sample application that demonstrates what I have explained above.
Please test the sample on your side and let me know if you have any questions.
Regards, Ivan Kitanov
TextEditorInGridCaptureTextONntering.zip
Hello Ivan,
thanks for the details.
I modified the sample, the way m using it. I followed infragistics legacy code for this.
please get the sample from the following link
https://drive.google.com/file/d/1b_Bon36eGnse7jMmrugmzV4-6daXX2ZO/view?usp=sharing
here, UltraGrid1_CellChange is not triggering , please check.
So the issue here is that you are using an UltraControlContinerEditor. In the typical case, the grid has an EditorWithText in the cell. And the griid knows how to trap when the user types into an EditorWithText cell. The EditorWithText fires a notification when this happens, so the grid can listen in and fire CellChange. With an UltraControlContinerEditor, your EditingControl could be anything. It could have one TextBox or twenty TextBoxes, or zero TextBoxes. It could have Checkboxes or grids or anything else you can imagine. So there's no way the grid can possibly know that the "Text" - if there even is text - have changed.
So what you should probably do is add an event to your ucTextCol. Or, since UserControl already has a TextChange event, you could just use that. Then when the ultraTextEditor1_TextChanged fires, you fire that event.
The simplest thing to do at that point would be for your form to just hook that event and then user the grid.ActivelCell so you can see which cell is changing - rather than using the CellChange event of the grid. Of course, you will probably also want to limit when this event fires. You don't want it to fire when you are initialing the text of the control for the cell, nor when you reset it. Only when the user is typing. So you will likely need to use a flag to differentiate those cases so you know when you are setting it internally.
If you really want the CellChange event of the grid to fire and don't want to use an event of your EditingControl, then you will have to jump through a few more hoops. For a start, you can't use the UltraControlContainer component, because you will need to be able to tell the editor to trigger the ValueChanged notification when the user types, and for that, you need to use the ControlContianerEditor class, instead. You will still need your form to hook into the TextChanged (or whatever event you choose) of your EditingControl. But then instead of handling it directly, you just triggger the RaiseValueChanged method on the derived ControlContianerEditor class. And that will fire TextChanged. I am attaching a working version of your sample for your reference. Please let me know if you have any questions of it anything here is unclear.
TextEditorInGridCaptureTextONntering Sample.zip
Thanks Mike for the suggestions and sample.
It worked !!!!!!!!!!!!!!
Hi Lizzy,
I'm glad that you were able to resolve your issue with the suggestion above.
Please don't hesitate to reach back if you have any questions.
Regards,Ivan Kitanov
So... if you ONLY want the color to change when the user is typing (the cell is in edit mode and the UltraTextEditor has focus), then it seems to me that you could handle that inside the UserControl code itself. You could trap the TexttChanged event of the UltraTextEditor and handle it right there.
If you want the text to be red when the user types something invalid OR when the text of a cell is invalid even when it's not in edit mode, then what I would do is take the sample I send you and simply re-factor the code from InitializeRow into a helper method. Then you would call that same method from InitializeRow (for cells not in edit mode) and also from CellChange (so that the same code is triggered when the user types in the cell).
EDIT: It looks like that second approach doesn't work. Applying an Appearance to the cell while it's in edit mode doesn't re-apply the appearance to the EditingControl. So you would have to do a little bit more work there.
I updated the sample once again to force the EditingControl to update immediately as you type.
8524.TextEditorInGridCaptureTextONntering Sample01.zip
Lizzy De said:I wanted whenever user type some specific letters , the forcolor of ultraTextEditor should be RED otherwise BLACK.
I mean while typing itself the forecolor should change according to condition.
Mike Saltzman said:I'm still not sure what you are trying to do. Can you please clarify exactly what you want to achieve here?
I wanted whenever user type some specific letters , the forcolor of ultraTextEditor should be RED otherwise BLACK.
Mike Saltzman said:The code you have here will do nothing, because ApplyOwnerAppearanceToEditingControl and ApplyOwnerAppearanceToRenderingControl default to true. So this code is a no-op that just sets these properties to the values they already have.
got it
Mike Saltzman said:You have some really strange code in here that I don't understand in the UltraGrid1_CellChange. I can't see how exiting edit mode inside this event makes any sense. You would end up leaving edit mode as soon as the user typed any single character, so I am baffled as to what you were trying to do there.
CellChange event is used to list the user typed letters with some condition.
I'm still not sure what you are trying to do. Can you please clarify exactly what you want to achieve here?
The code you have here will do nothing, because ApplyOwnerAppearanceToEditingControl and ApplyOwnerAppearanceToRenderingControl default to true. So this code is a no-op that just sets these properties to the values they already have.
You have some really strange code in here that I don't understand in the UltraGrid1_CellChange. I can't see how exiting edit mode inside this event makes any sense. You would end up leaving edit mode as soon as the user typed any single character, so I am baffled as to what you were trying to do there.
Your InitializeRow code makes sense. And I can see that you are applying an appearance to the cells of the grid. That's good. These appearance settings will get applied to the EditingControl and the RenderingControl. But keep in mind that your EditingControl is the UserControl (utc1 and utc2). So if you were to set the BackColor of the cell, that would work since the majority of the cell is showing the UserControl's background. But setting the ForeColor on the UserControl will not affect the ForeColor of the TextBox (or UltraTextEditor) inside the UserControl. I see that you also added code to change the ForeColor of the UtraTextEditor of the UserControl, but the code was commented out. That's the right thing to do, but InitializeRow is the wrong place to do it, since the RenderingControl and EditingControl are shared amongst all the cells in the column. So that's where the ApplyOwnerAppearance comes in.
I have attached an updated sample here the works.
So the first thing I did here was remove the CellChange event code, because I just don't get what you were trying to do there. I changed InitializeRow to set (or reset) the ForeColor and BackColor of the cell based on the value. Note that it's always a good idea to set BOTH ForeColor and BackColor. If you set one without the other, you run the risk of setting the, both to the same color and then the user can't see the text.
I ALSO set the SelectedAppearance and ActiveAppearance on the cells. If you don't do this, then when you run the sample, you will not see the colors applied to the first row cell(s), because the active appearance (the white-on-blue windows highlight colors) will override the cell settings.
Finally, I overrode ApplyOwnerAppearance on the ControlContainerEditor. There, I get the resolved appearance settings and apply them to the UltraTextEditor inside the UserControl.
TextEditorInGridCaptureTextONntering Sample01.zip
Hi Mike,
My requirment required particular forecolor for the user input, I tried the suggested options in the following sample:
https://drive.google.com/file/d/1m_e54uwWTlrB1VVhB6scJ1MDS9FFXp1N/view?usp=sharing
myControlContainerEditor.ApplyOwnerAppearanceToEditingControl = true; myControlContainerEditor.ApplyOwnerAppearanceToRenderingControl = true;
I am not getting the required output, might be my way to approach the suggestions is not in correct way.