KB Article T904229
Visible to All Users

Values in Data Editors - WinForms Cheat Sheet

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.

dk-editors-sctructure.png

At runtime, these objects are used as templates from which real editors are created. This technique enables two things:

  1. 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 the GridColumn.ColumnEdit property.

  2. 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
Code Example
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?

Code Example
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?

Code Example
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.


Help us improve this article

Comments (2)

    @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!

    DevExpress Support Team 5 years ago

      Thank you, Alex. More on the way!

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.