Results 1 to 4 of 4

Thread: (VS2010) How can I: Datagridview specific column data to change search box color

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    3

    (VS2010) How can I: Datagridview specific column data to change search box color

    I have a VB form with a local database containing contacts. I have one column that specifies if the contact is local or not . I would like to make it so that if the user searches for a specific contact, it will check the specific column and change the search box color accordingly.. (Red for not local contact, Green for yes)

    I have created a query with the database using Contact_Name LIKE ? + '%'
    Which is the search box I want for color changing per column data.
    and thought I could add an "If" statement there. So far I've tried using

    Code:
    If Datagridviewcolumn.Equals("Yes") Then
    Param1ToolStripTextBox.BackColor = Color.LightGreen
    End If
    And

    Code:
    Datagridviewcolumn4.Contains
    But this isn't producing any action.


    Any help is appreciated. Thank you.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,430

    Re: (VS2010) How can I: Datagridview specific column data to change search box color

    How can a DataGridViewColumn be equal to "Yes"? One is a DataGridViewColumn and one is a String. What you care about is the Value of one cell in that column. Presumably this is happening when you select a particular row in the grid, although you haven't really explained that clearly. Assuming that, you might do something like this:
    Code:
    If CStr(myDataGridView.CurrentRow.Cells(4).Value) = "Yes" Then

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    3

    Re: (VS2010) How can I: Datagridview specific column data to change search box color

    Thank you for your response.
    But this Code:

    Code:
    If CStr(myDataGridView.CurrentRow.Cells(4).Value) = "Yes" Then
    Provides no action either.

    I'm sorry if I didn't explain it clearly. What I'm trying to achieve is after a user searches for a contact, I want it to check the value of Column "Local Contact" (cell containing yes or no) of the current row. Based on yes or no, it will change an objects back color.

    I'm currently trying this:

    Code:
    If CStr(ContactsDataGridView.CurrentRow.Cells.Item("Local Contact").Value) Is "Yes" Then
                Param1ToolStripTextBox.BackColor = Color.LightGreen
            End If
    But I get
    Column named Local Contact cannot be found.
    Parameter name: columnName
    Last edited by Jiero; Jan 3rd, 2015 at 07:45 PM.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,430

    Re: (VS2010) How can I: Datagridview specific column data to change search box color

    The issue is obvious then: you have no column with that name. The text you see in the header of the column in the UI is NOT the name. If you want to get a column by name then you have to provide the value of the Name property of that column, not the value of its HeaderText property.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width