Events of DevExpress GridView Control.

Introduction :

This Blog demonstrates the events of DevExpress GridView Control.

GridControl supports single row selection,multiple row selection and multiple cell selection modes.

Explanation :

1.ColumnView.FocusedRowHandle :Specifies the focused row's handle. This property allows we to get the focused and selected row.Assiging a value to this property focuses and select the specified row.
2.ColumnView.SelectAll :Selects all rows within the View.
3.ColumnView.SelectedRowsCount:Returns the number of the currently selected rows.
A single row can be focused and selected in this mode, so this property always returns -1.
4.ColumnView.GetSelectedRows :Returns an array of the handles of the selected rows.
In this selection mode, it returns an array that contains a single element and this identifies the focused row's handle.
5.ColumnView.FocusedRowChanged :Fires in response to changing row focus.

public event FocusedRowChangedEventHandler FocusedRowChanged;
private void gridView1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) {
      if (gridView1.IsGroupRow(e.FocusedRowHandle)) {
         bool expanded = gridView1.GetRowExpanded(e.FocusedRowHandle);
         gridView1.SetRowExpanded(e.FocusedRowHandle, !expanded);

6.GridControl.ColumnsPopulated :Populates the columns of grid.

 void DataGridControl_ColumnsPopulated(object sender, DevExpress.Xpf.Core.WPFCompatibility.SLRoutedEventArgs e)
             string headercolumn;
             for (int i = 0; i < DataGridControl.Columns.Count; i++)
                 DevExpress.Xpf.Grid.GridColumn v = DataGridControl.Columns[i];
                 headercolumn = v.FieldName.ToString();

7.GridControl.CustomColumnDisplayText : Displaying the columns text.

 void DataGridControl_CustomColumnDisplayText(object sender, DevExpress.Xpf.Grid.CustomColumnDisplayTextEventArgs e)
             if (e.Column.FieldName.StartsWith("m"))
                 decimal price = Convert.ToDecimal(e.DisplayText);
                 decimal? inputDecimal = price as decimal?;
                 e.DisplayText = "$ " + inputDecimal.Value.ToString("N2", ciUSA);
             if (e.Column.FieldName.StartsWith("dt"))
                 String input = e.DisplayText.ToString();
                 if (input != null && input != "")
                     string myDate = e.DisplayText.ToString();
                     DateTime myDateTime = DateTime.Parse(myDate);
                     e.DisplayText = myDateTime.ToString("d");
Next Recommended Reading DataGrid.LoadingRow Event in silverlight