Solved

DataGridViewComboBoxCell Color Based on List

Posted on 2010-08-17
4
589 Views
Last Modified: 2012-05-10
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
Comment
Question by:diablo089
  • 3
4 Comments
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 250 total points
ID: 33457822
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
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33457832
Declare combo:
Private Combo as combobox
0
 

Author Comment

by:diablo089
ID: 33457945
Hmm... This is going to make my combobox column look like a textbox column with no drop down arrow, isn't it?
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33457975
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vb.net 2 45
Close tabpage of custom control 9 37
Import a txt file into a DataGridView and TextBox 20 40
Help with consolidating excel files using VB.net 2 26
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question