Solved

DataGridViewComboBoxCell Color Based on List

Posted on 2010-08-17
4
595 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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