Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The trick to force the UltraGrid to use different editors for cells in the same column is based on a set of programming objects and patterns offered by the infrastructure of the control.</p> <p>The first thing is to consider is the <code>InitializeRow</code> event. This event is called for each row when you set the initial DataSource of the grid or when you change something in the underlying DataSource. You can differentiate between the two situations thanks to the <code>e.Reinitialize</code> flag. If it is false, then the whole datasource is applied to the grid, if it is true then only a subset of rows are reinitialized usually because the user has edited the cell or the code has changed a value in the datasource. </p> <p>The second thing to consider is the <code>Editor</code> property present in every UltraGridCell or UltraGridColumn. It is an object that is built automatically by the UltraGrid to allow the cell editing. The UltraGrid code set this object based on the datatype of the column and, obviously, sets the same editor for every cell of the column. You could set your own editor at the column level (usually in the <code>InitializeLayout</code> event) or on cell by cell basis looking at your formatting rule.</p> <p>Let's try an example (Big parts of this is taken from the example code suggested in its comments by Alhalama)</p> <p>Suppose you have a DataTable with only two columns: First column is called <code>CONDITION</code> and contains a string. This string is my formatting requirement.<br> The second column is called <code>DATEINFO</code> and contains the dates that should be formatted differently accordingly to the value in the column CONDITION.<br> So if <code>CONDITION = 'TEST1'</code> then the DATEINFO cell is formatted with Day/Month/Year pattern, if the <code>CONDITION='TEST2'</code> then the DATEINFO cell should be formatted with Hour/Minute/Seconds. </p> <pre><code>private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { if (e.ReInitialize == false) { DefaultEditorOwnerSettings editorSettings; DateTimeEditor datetime_editor; string condition = e.Row.GetCellValue("Condition").ToString(); switch (condition) { case "TEST1": editorSettings = new DefaultEditorOwnerSettings() editorSettings.DataType = typeof(DateTime); editorSettings.MaskInput = "mm/dd/yyyy"; datetime_editor = new DateTimeEditor(new DefaultEditorOwner(editorSettings)); e.Row.Cells["DateInfo"].Editor = datetime_editor; break; case "TEST2": editorSettings = new DefaultEditorOwnerSettings() editorSettings.DataType = typeof(DateTime); editorSettings.MaskInput = "hh:mm:ss"; datetime_editor = new DateTimeEditor(new DefaultEditorOwner(editorSettings)); e.Row.Cells["DateInfo"].Editor = datetime_editor; break; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload