Other DevExpress WinForms Cheat Sheets
All DevExpress WinForms Editors are BaseEdit descendants that have the EditValue property. EditValue is an internally stored editor value that may differ from text end-users see. For instance, a TextEdit with EditValue
of "20" can display "$20.00" because this editor has an active currency mask. To change the current editor value, always use the EditValue
property, not Text
, DisplayText
or other public editor properties.
Editors store their core settings inside RepositoryItem objects.
At runtime, these objects are used as templates from which real editors are created. This technique enables two things:
-
Editors can be embedded into container controls like Bars or Ribbon and data-aware controls like Gantt Control, Data Grid, Tree List, Vertical Grid, etc. To display an editor within a Ribbon or Toolbar, create a BarEditItem and assign a RepositoryItem to its
Edit
property. To use a required editor as an in-place editor for each Data Grid cell under the given column, assign a related RepositoryItem to theGridColumn.ColumnEdit
property. -
Controls that embed editors do not need to keep hundreds and thousands of real editors. Instead, when an editor is needed (for instance, when a user clicks a Grid cell to edit its value), the control creates an editor based on the assigned RepositoryItem. Similarly, when the editor is no longer needed (user moves focus away from the cell), it is automatically disposed (see Default Cell Editors).
To read and modify values of editors embedded in Ribbon or Bars, use BarEditItem.EditValue. Data-aware controls expose ~SetCellValue / ~SetRowCellValue methods for the same task. For instance, in DataGrid you can use methods described in this help article: Read and Modify Cell Values in Code.
When users edit editor values, the RepositoryItem.EditValueChanging and RepositoryItem.EditValueChanged events fire. EditValueChanging
allows you to cancel this change before it was accepted. EditValueChanged
occurs after the new value is set, and allows you to respond to this change.
Examples
How to insert text at a specific position in TextEdit?
- Use
EditValue
to get the the currently displayed text - Modify this value and assign it back to the
EditValue
property
C#string currentText = string.Empty;
if (textEdit1.EditValue != null)
currentText = textEdit1.EditValue.ToString();
int startIndex = currentText.IndexOf("insert");
textEdit1.EditValue = currentText.Insert(startIndex, "Test");
What data type in an SQL table is appropriate for a column with ColorPickEdit?
ColorPickEdit editor's EditValue
property accepts integer values (represent colors in RGB formats) and Color values.
Refer to the following help topic to learn more: ColorPickEdit.EditValue.
How do I set the value of SearchLookUpEdit embedded in Ribbon?
Modify the BarEditItem.EditValue property of a BarEditEdit that hosts this SearchLookUpEdit.
How to modify the ButtonEdit's value on a button click?
- Handle RepositoryItemButtonEdit.ButtonClick event
- Cast sender to the
ButtonEdit
type - Modify the sender's
EditValue
property
C#private void button_Click(object sender, ButtonPressedEventArgs e) {
ButtonEdit buttonEdit = sender as ButtonEdit;
buttonEdit.EditValue = "Your value";
}
Can the DateEdit's Today button assign the current date and time to the editor, rather than scroll a drop-down calendar to this day?
- Handle the TodayClick event
- Assign a required value to the EditValue property
- If needed, call your code inside the Control.BeginInvoke > method to postpone the assignment.
C#private void dateEdit1_Properties_TodayClick(object sender, EventArgs e) {
BeginInvoke(new MethodInvoker(() => {
dateEdit1.EditValue = DateTime.Now;
}));
}
If the DateEdit editor is used for in-place editing, use the ActiveEditor property (TreeList.ActiveEditor, VGridControl.ActiveEditor, BarManager.ActiveEditor, etc.) to obtain the editor instance that you should use instead of "dateEdit1" in the code sample above.
@Stas and @Sasha Just want to mention that the 'Cheat Sheet' series is a welcome addition. Concise and just the right amount of information. Well done guys!
Thank you, Alex. More on the way!