|
To dynamically set style properties on a cell, the QueryCellStyleInfo event has to handled. We access the row of the cell and check if it is a RecordRow. Assuming the datasource is a DataTable, the GridRecordRow.Record.GetData method returns the data as a DataRowView object. Then by using the DataRowView we can access the data in the row and after checking conditions, we can change the style of the row. C# //disabling the row when the value of Name in the same row is Row1. private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) { if(e.TableCellIdentity.RowIndex!=-1) { GridRecordRow rec = this.gridGroupingControl1.Table.DisplayElements[e.TableCellIdentity.RowIndex] as GridRecordRow; if(rec != null) { DataRowView dr = rec.GetData() as DataRowView; if(dr != null && dr["Name"].Equals("Row1")) e.Style.Enabled = false; } } } VB 'disabling the row when the value of Name in the same row is Row1. Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs) Handles gridGroupingControl1.QueryCellStyleInfo If e.TableCellIdentity.RowIndex <> -1 Then Dim rec As GridRecordRow = CType(IIf(TypeOf Me.gridGroupingControl1.Table.DisplayElements(e.TableCellIdentity.RowIndex) Is GridRecordRow, Me.gridGroupingControl1.Table.DisplayElements(e.TableCellIdentity.RowIndex), Nothing), GridRecordRow) If Not rec Is Nothing Then Dim dr As DataRowView = CType(IIf(TypeOf rec.GetData() Is DataRowView, rec.GetData(), Nothing), DataRowView) If Not dr Is Nothing AndAlso dr("Name").Equals("Row1") Then e.Style.Enabled=False End If End If End If End Sub Sample: http://websamples.syncfusion.com/samples/kb/grid.windows/GGCConditionalRowStyle/main.htm |