HOME PAGE | DOWNLOAD | TUTORIALS | XtraReports
Devexpress

Sunday, July 22, 2012

How to: Dynamically Control Record Visibility in XtraGrid

The following code shows how to make the rows that contain the "USA" value in the 'Country' field always visible regardless of the filter applied to a View. The ColumnView.CustomRowFilter event is handled to control the visibility of the rows.

C#

using DevExpress.XtraGrid.Views.Base;

using DevExpress.XtraGrid.Views.Grid;

 

private void gridView1_CustomRowFilter(object sender, RowFilterEventArgs e) {

   GridView view = sender as GridView;

   DataView dv = view.DataSource as DataView;

   // Check whether the current row contains "USA" in the "Country" field.

   if((string)dv[e.ListSourceRow]["Country"] == "USA") {

      // Make the current row visible.

      e.Visible = true;

      // Prevent default processing, so the row will be visible

      // regardless of the view's filter.

      e.Handled = true;

   }

}

 

VB

Imports DevExpress.XtraGrid.Views.Grid
 
Private Sub GridView1_CustomRowFilter(ByVal sender As Object, _
  ByVal e As DevExpress.XtraGrid.Views.Base.RowFilterEventArgs) _
  Handles GridView1.CustomRowFilter
   Dim view As GridView = CType(sender, GridView)
   Dim dv As DataView = view.DataSource
   ' Check whether the current row contains "USA" in the "Country" field.
   If CStr(dv(e.ListSourceRow)("Country")) = "USA" Then
      ' Make the current row visible.
      e.Visible = True
      ' Prevent default processing, so the row will be visible 
      ' regardless of the view's filter.
      e.Handled = True
   End If
End Sub

 

No comments:

Post a Comment