2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Solution: To change the image of a cell at runtime based on the value of the adjacent cell, you can make use of PrepareViewStyleInfo and CurrentCellCloseDropDown events. In the following code, when you are selecting the value in the combo box placed in the first row of the fourth column, the appropriate image is shown in the first row of the fifth column. C# this.gridDataBoundGrid1.PrepareViewStyleInfo += gridDataBoundGrid1_PrepareViewStyleInfo; this.gridDataBoundGrid1.CurrentCellCloseDropDown += gridDataBoundGrid1_CurrentCellCloseDropDown; void gridDataBoundGrid1_CurrentCellCloseDropDown(object sender, Syncfusion.Windows.Forms.PopupClosedEventArgs e) { //Get the current cell value. cc = this.gridDataBoundGrid1.CurrentCell; newvalue = cc.Renderer.GetCellValue().ToString(); this.Refresh(); } void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e) { if (e.RowIndex == 1 && e.ColIndex == 4) { //Set the items to the combobox. e.Style.CellType = "ComboBox"; e.Style.DataSource = items; } else if (e.RowIndex == 1 && e.ColIndex == 5) { //Set the cell type as image. e.Style.CellType = GridCellTypeName.Image; e.Style.ImageList = this.imageList; if (newvalue == "s2") e.Style.ImageIndex = 1; else if (newvalue == "s3")//New value is obtained from GridCurrentCell renderer. e.Style.ImageIndex = 2; else e.Style.ImageIndex = 0; } } VB Private Me.gridDataBoundGrid1.PrepareViewStyleInfo += AddressOf gridDataBoundGrid1_PrepareViewStyleInfo Private Me.gridDataBoundGrid1.CurrentCellCloseDropDown += AddressOf gridDataBoundGrid1_CurrentCellCloseDropDown Private Sub gridDataBoundGrid1_CurrentCellCloseDropDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.PopupClosedEventArgs) 'Get the current cell value. cc = Me.gridDataBoundGrid1.CurrentCell newvalue = cc.Renderer.GetCellValue().ToString() Me.Refresh() End Sub Private Sub gridDataBoundGrid1_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs) If e.RowIndex = 1 AndAlso e.ColIndex = 4 Then 'Set the items to the combobox e.Style.CellType = "ComboBox" e.Style.DataSource = items ElseIf e.RowIndex = 1 AndAlso e.ColIndex = 5 Then 'Set the celltype as image e.Style.CellType = GridCellTypeName.Image e.Style.ImageList = Me.imageList If newvalue = "s2" Then e.Style.ImageIndex = 1 ElseIf newvalue = "s3" Then 'New value is obtained from GridCurrentCell renderer. e.Style.ImageIndex = 2 Else e.Style.ImageIndex = 0 End If End If End Sub After applying the properties, the grid is shown as follows, Figure 1: Output Sample Link: C#: Image VB: Image |
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.