Category / Section
How to hide a particular cell based on the value of another cell in the same row?
1 min read
To hide a particular cell or make it a static cell based on the cell value of the another cell in the same row, it can be handled by QueryCellInfo event. The cell type can be declared as `Static` to avoid making modification of the cell.
this.gridDataBoundGrid1.Model.QueryCellInfo += Model_QueryCellInfo; } private void Model_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e) { if (e.RowIndex > 0 && e.ColIndex > 0) { if (e.ColIndex == 1 && e.RowIndex != this.gridDataBoundGrid1.Model.RowCount) { //assign the value of the column from hash collection table if (table.ContainsKey(e.RowIndex) && table[e.RowIndex] != e.Style.CellValue) table[e.RowIndex] = e.Style.CellValue; else if (!table.ContainsKey(e.RowIndex)) table.Add(e.RowIndex, e.Style.CellValue); } //check the condition the static cell if (e.ColIndex == 2 && table.Count > 0 && table.ContainsKey(e.RowIndex) && (int)table[e.RowIndex] % 2 == 0) { e.Style.CellType = "static"; //To avoid modifying. e.Style.TextColor = e.Style.BackColor; e.Style.CellAppearance = Syncfusion.Windows.Forms.Grid.GridCellAppearance.Raised; } }
Private Me.gridDataBoundGrid1.Model.QueryCellInfo += AddressOf Model_QueryCellInfo } Private Sub Model_QueryCellInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs) If e.RowIndex > 0 AndAlso e.ColIndex > 0 Then If e.ColIndex = 1 AndAlso e.RowIndex <> Me.gridDataBoundGrid1.Model.RowCount Then 'assign the value of the column from hash collection table If table.ContainsKey(e.RowIndex) AndAlso table(e.RowIndex) <> e.Style.CellValue Then table(e.RowIndex) = e.Style.CellValue ElseIf Not table.ContainsKey(e.RowIndex) Then table.Add(e.RowIndex, e.Style.CellValue) End If End If 'check the condition the static cell If e.ColIndex = 2 AndAlso table.Count > 0 AndAlso table.ContainsKey(e.RowIndex) AndAlso CInt(Fix(table(e.RowIndex))) Mod 2 = 0 Then e.Style.CellType = "static" 'To avoid modifying. e.Style.TextColor = e.Style.BackColor e.Style.CellAppearance = Syncfusion.Windows.Forms.Grid.GridCellAppearance.Raised End If End If
Screenshot
Sample