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.
It's not exactly clear to me what you are asking.
The UltraControlContainer will apply certain basic appearance properties to the EditingControl and the RenderingControl. This includes BackColor, ForeColor, and Font, I think. So if you just use the InitializeRow event of the grid to apply an Appearance to the cell, that should do a lot for you.
I'm pretty sure that ForeColor and Font are automatically picked up from the parent control, so UltraTextEditor should pick those up. So that would just leave BackColor. If you want the BackColor of the UltraTextEditor to pick up the BackColor of the cell/UserControl, then you could just set the UltraTextEditor.Appearance.BackColor to Transparent. If you want more fine control over the appearance of the child controls, then you could override ApplyOwnerAppearance on your derived ControlContrainerEditor class.
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.
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
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.
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.
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