[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 607
  • Last Modified:

DataGridViewComboBoxCell Color Based on List

Is it possible to change the background draw color of a DataGridViewComboBoxCell based on a list of colors in the list? I've put the names of about 15 system colors in a DataGridViewComboBoxColumn collection, and I'd like to know if it's possible to color those items in the list based on those names.
0
diablo089
Asked:
diablo089
  • 3
1 Solution
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
with a little doubt about how possible is that a trick is to add a handler and change your comboboxcolumn display style to nothing like a textbox column ..
use editing control showing event
something like this
Private Sub MyDataGridView_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles MyDataGridView.EditingControlShowing

        Try

            combo = CType(e.Control, ComboBox)

            If (combo IsNot Nothing) Then


                RemoveHandler combo.DropDownClosed, New EventHandler(AddressOf ComboBox_DropDownClosed)
                AddHandler combo.DropDownClosed, New EventHandler(AddressOf ComboBox_DropDownClosed)


                

            End If


        Catch ex As InvalidCastException

        Catch ex As Exception

            MsgBox(ex.ToString)

        End Try

    End Sub

Private Sub ComboBox_DropDownClosed(ByVal sender As Object, ByVal e As EventArgs)

        ¿t¿
        Try

            If  Me.MyDataGridView.CurrentRow.Cells("YourComboboxColumnIndex").IsInEditMode Then
                

                

                Dim col As New DataGridViewComboBoxCell
                col = Me.MYDataGridView.CurrentRow.Cells("YourComboboxColumnIndex" )
                col.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
                col.Style.BackColor = Color.Red
                
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            End If

        Catch ex As ArgumentException

        Catch ex As Exception

            MsgBox(ex.ToString)

        End Try

    End Sub

Open in new window

0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Declare combo:
Private Combo as combobox
0
 
diablo089Author Commented:
Hmm... This is going to make my combobox column look like a textbox column with no drop down arrow, isn't it?
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Untill You get in again ...and select something else
I really do not know if there is other way to do it ..
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now