0

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?

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by JJCollins
0

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

Edited by JJCollins: n/a

0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.