2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Change the color of button edit cellYou can change the color of the ButtonEdit cell while clicking, by using the CellMouseUp and MouseDown events. The following code examples are used for changing ButtonEdit color in CellMouseUp and MouseDown events. C# ButtonEditStyleProperties sparam; // Adding new ButtonEditCell model to grid. this.gridDataBoundGrid1.Model.CellModels.Add("ButtonEdit", new ButtonEditCellModel(this.gridDataBoundGrid1.Model)); // Gets ProductName column style. GridStyleInfo styleparam = this.gridDataBoundGrid1.Binder.InternalColumns["ProductName"].StyleInfo; // changing Celltype for ProductName column. styleparam.CellType = "ButtonEdit"; //Geting ButtonEditStyleProperties for ProductName column style. sparam = new ButtonEditStyleProperties(styleparam); sparam.ButtonEditInfo.BackColor = Color.Orange; sparam.ButtonEditInfo.Text = "Edit-Method"; sparam.ButtonEditInfo.TextColor = Color.White; //Hooking CellMouseUp event. this.gridDataBoundGrid1.CellMouseUp += new GridCellMouseEventHandler(gridDataBoundGrid1_CellMouseUp); //Hooking MouseDown event. this.gridDataBoundGrid1.MouseDown += new MouseEventHandler(gridDataBoundGrid1_MouseDown); void gridDataBoundGrid1_MouseDown(object sender, MouseEventArgs e) { int rowindex, colindex = 0; this.gridDataBoundGrid1.ViewLayout.PointToClientRowCol(e.Location, out rowindex, out colindex,true); if (this.gridDataBoundGrid1[rowindex, colindex].CellType == "ButtonEdit") { // Used to change the color while clicking on it. sparam.ButtonEditInfo.BackColor = Color.Red; } } void gridDataBoundGrid1_CellMouseUp(object sender, GridCellMouseEventArgs e) { if (this.gridDataBoundGrid1[e.RowIndex, e.ColIndex].CellType == "ButtonEdit") { // Used to retrieve the old color after clicking. sparam.ButtonEditInfo.BackColor = Color.Orange; } } VB Dim sparam As ButtonEditStyleProperties ' Adding new ButtonEditCell model to grid. Me.gridDataBoundGrid1.Model.CellModels.Add("ButtonEdit", New ButtonEditCellModel(Me.gridDataBoundGrid1.Model)) ' Gets ProductName column style. Dim styleparam As GridStyleInfo = Me.gridDataBoundGrid1.Binder.InternalColumns("ProductName").StyleInfo ' changing Celltype for ProductName column. styleparam.CellType = "ButtonEdit" 'Geting ButtonEditStyleProperties for ProductName column style. sparam = New ButtonEditStyleProperties(styleparam) sparam.ButtonEditInfo.BackColor = Color.Orange sparam.ButtonEditInfo.Text = "Edit-Method" sparam.ButtonEditInfo.TextColor = Color.White 'Hooking CellMouseUp event. Private Me.gridDataBoundGrid1.CellMouseUp += New GridCellMouseEventHandler(AddressOf gridDataBoundGrid1_CellMouseUp) 'Hooking MouseDown event. Private Me.gridDataBoundGrid1.MouseDown += New MouseEventHandler(AddressOf gridDataBoundGrid1_MouseDown) Private Sub gridDataBoundGrid1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Dim rowindex As Integer, colindex As Integer = 0 Me.gridDataBoundGrid1.ViewLayout.PointToClientRowCol(e.Location, rowindex, colindex,True) If Me.gridDataBoundGrid1(rowindex, colindex).CellType Is "ButtonEdit" Then ' Used to change the color while clicking on it. sparam.ButtonEditInfo.BackColor = Color.Red End If End Sub Private Sub gridDataBoundGrid1_CellMouseUp(ByVal sender As Object, ByVal e As GridCellMouseEventArgs) If Me.gridDataBoundGrid1(e.RowIndex, e.ColIndex).CellType Is "ButtonEdit" Then ' Used to retrieve the old color after clicking. sparam.ButtonEditInfo.BackColor = Color.Orange End If End Sub In the following screenshot, ButtonEdit color is changed while clicking. Figure 1: ButtonEdit color changed during clicking Note: The provided sample illustrates the functionality of GridDataBoundGrid alone. Similarly, you can apply the provided code example for GridControl to achieve the same behavior. Samples: |
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.