954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

"Field Has Focus" conditional formatting in Access. How in VB?

In MS Access you can set the background to a specific colour when the field has the focus. This is done through "conditional formatting", using the "Field has Focus" feature.

How is that done in VB.NET?

PerplexedB
Newbie Poster
20 posts since Sep 2010
Reputation Points: 10
Solved Threads: 2
 

Just some sample code for you, edit as you wish (I think this is right from what I understand from your post)

Protected Sub GridView1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.GridItemEventArgs)
           'Is it a GridDataItem
           If (TypeOf (e.Item) Is GridDataItem) Then
               'Get the instance of the right type
               Dim dataBoundItem As GridDataItem = e.Item

               'Check the formatting condition
               If (Integer.Parse(dataBoundItem( "Size").Text) > GridItemType.Footer) Then
                  dataBoundItem( "Received").ForeColor = Color.Red
                  dataBoundItem( "Received").Font.Bold = True
                    'Customize more...
               End If
           End If
JJCollins
Junior Poster in Training
67 posts since Sep 2010
Reputation Points: 14
Solved Threads: 10
 

Tnanks Jordan. But this is still somewhat too advanced for me.

This on the other hand seems to do the trick (in a maskedtextbox).

Public Class txtBase
    Inherits System.Windows.Forms.MaskedTextBox
    Dim nSaveColor As Color

    Private Sub txtBase_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
        Me.nSaveColor = Me.BackColor
        Me.BackColor = Color.Turquoise
    End Sub

    Private Sub txtBase_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
        Me.BackColor = Me.nSaveColor
    End Sub
End Class


Well.... it seems to work. I'll wait some time before I set this thread as "solved". What do you think?

PerplexedB
Newbie Poster
20 posts since Sep 2010
Reputation Points: 10
Solved Threads: 2
 

Are you trying to do it to a GridView or just a simple textbox?

- Jordan

JJCollins
Junior Poster in Training
67 posts since Sep 2010
Reputation Points: 14
Solved Threads: 10
 

Just a simple textbox (at this time).

PerplexedB
Newbie Poster
20 posts since Sep 2010
Reputation Points: 10
Solved Threads: 2
 

If you're trying to do it conditionally

If blah = true then
textbox1.focus()
textbox1.backcolor = drawing.color.azure
endif


or are you trying to get the textbox to change colour when you click inside it?

Also, I'd recommend reading this to gain a better understanding of what you're trying to accomplish :) http://www.dotnetspider.com/resources/19980-Custom-OnFocus-Textbox-Control.aspx

- Jordan

JJCollins
Junior Poster in Training
67 posts since Sep 2010
Reputation Points: 14
Solved Threads: 10
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: