Removing blue background of focus

I'm using a DataGridView control, and have a column that contains comboboxes. Depending on the selection that is made in the comboboxes, I want the backcolor to be set to a particular colour. However, when this the selection is made, the backcolor is in blue (as it is in focus) and conceals the colour that has been set until the focus changes.

Is there any way I can remove the blue back ground colour of focus, so the colour shows immediately on selection Or is there a means to set the focus to somethingelse

Thanks in advance,

Michael



Answer this question

Removing blue background of focus

  • Winthrop Chan

    I don't know if this is the best way, as I am new to VB, but it worked for my particular form. I had one button that I always changed the Focus to, but I did not want the blue highlight either.

    Here is what I used to change the Focus:

    Private Sub SetDefault(ByVal WhichButton As Button)

    Me.ActiveControl = WhichButton

    End Sub

    Now you can CALL that procedure when you need to reset the button focus:

    Call SetDefault(FocusButton)

    Here is what someone else suggested after I found that solution:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    OtherControlName.Focus()

    ' Button1 stuff here...

    End Sub

    So... to hide the focus, I built another button and hid it underneath another button(Right Click, Send to Back), and then changed the focus to that button.

    Now, anytime another button is clicked, the focus is sent to a hidden button that does nothing.

    I'd love it if someone actually knows how to turn off the highlight.


  • Clay Budin

    Nice thing is with VB2005, we don't have to do funky things with focus, Mystikef, which was often the easiest solution with VB6 (without resorting to subclassing). We have lots of events to play with: In particular, RowPrePaint is a really useful one.

    The following link demonstrates a gradient background that I have certainly got bookmarked:

    http://msdn2.microsoft.com/en-us/library/85kxk29c.aspx

    It may not do precisely what you want, but wil demonstrate the amount of control you have in how the control appears (is rendered), and will be easily be modified.



  • Removing blue background of focus