Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vb.net 2008 - how to highlight a specific row in a datagridview

Posted on 2011-02-24
9
Medium Priority
?
1,066 Views
Last Modified: 2012-05-11
I'm looping through the rows in my datagridview and want to highlight one when I find a certain match.  How do I do that last part?  See commented line below.

       Dim myrow As DataGridViewRow
        For x = 0 To Me.DataGridView1.Rows.Count
            myrow = DataGridView1.Rows(x)
            If myrow.Cells(0).Value.ToString.Trim = MatchingKeyCodeThen
                ' ?? Can't find command to highlight row(x).
                Exit For
            End If
        Next

TIA
0
Comment
Question by:jackiemeck
  • 4
  • 4
9 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34975080
use myrow.BackColor and myrow.ForeColor to change the colors so its highlighted in the way you want

myRow.BackColor = Drawing.Color.Crimson
myRow.ForeColor = Drawing.Color.White
0
 

Author Comment

by:jackiemeck
ID: 34975103
I'm sorry...I used an unclear term.   I have the datagridview property set (DataGridViewSelectionMode.FullRowSelect)  so that when one cell is clicked, the entire row is highlighted/selected.  I want to be able to manually select the current record when the user comes back to this screen, meaning, I need to simulate that the user clicked a specific row.  I don't believe the backcolor will mark this row "selected".
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34975231
try : myRow.ApplyStyle(DataGridView1.SelectedRowStyle)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 17

Accepted Solution

by:
nepaluz earned 2000 total points
ID: 34975255
try the currentcell

Me.DataGridView1.CurrentCell=MatchingKeyCode
0
 

Author Comment

by:jackiemeck
ID: 34975271
myrow.applystyle isn't pulling up as a supported function.  Neither does "selectedRowStyle" for DataGridView.  This is VB.net 2008...is that a new function?
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34975284
Hmm is this windows forms it is isn't it.
0
 

Author Comment

by:jackiemeck
ID: 34975301
Yes...Now I'm finding there are many differences between DataGrid and DataGridView...I'm using the latter.
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34975320
what about :

myrow.BackColor = SystemColors.Highlight
myrow.ForeColor = SystemColors.HighlightText
0
 

Author Comment

by:jackiemeck
ID: 34975364
I found it thanks to nepaluz...the following works, where 0 is the column position and x is the desired row:

 Me.DataGridView1.CurrentCell = Me.DataGridView1.Item(0, x)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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 …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

885 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