Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1429
  • Last Modified:

vb.net datagrid view row header selection

Hi, I am trying to get the row heaer selected but for some rason it does not work. (This little black arrow on the row selection on the left)

Here is my code that does the job and selects the row but not row header..

For Each row As DataGridViewRow In Me.DataGridView1.Rows
        If selectedLineNo = row.Cells.Item("LINENO").Value Then
        Me.DataGridView1.FirstDisplayedScrollingRowIndex = row.Index
        Me.DataGridView1.Refresh()
        Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(row.Index).Cells(0)
		Me.DataGridView1.Rows(row.Index).Selected = True
    Exit For
    End If
Next

Open in new window


Can you please tell me where is the problem?
Thank you for your answer
0
rkanabus
Asked:
rkanabus
  • 4
  • 3
1 Solution
 
PagodNaUtakCommented:
You want the row header to selected right? To do this just set the property of datagridview to FullRowSelect either at desgn time or programmatically...
DatagridView.SelectionMode = FullRowSelect┬┐
For Each row As DataGridViewRow In Me.DataGridView1.Rows  
        If selectedLineNo = row.Cells.Item("LINENO").Value Then  
        Me.DataGridView1.FirstDisplayedScrollingRowIndex = row.Index  
        Me.DataGridView1.Refresh()  
        Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(row.Index).Cells(0)  
                Me.DataGridView1.Rows(row.Index).Selected = True  
    Exit For  
    End If  
Next

Open in new window

0
 
rkanabusAuthor Commented:
I tried that, it does not work. The little black arrow does not appear. It selects the row but without the header. I need that other wise I am getting the following error message in another sub.

 Error
The sub works fine only when both rows from both datagrids are selected properly.
0
 
PagodNaUtakCommented:
Can you post an image you want to achieve...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
PagodNaUtakCommented:
Also make sure that the dataGridView1.RowHeadersVisible is set to true

dataGridView1.RowHeadersVisible = True
0
 
rkanabusAuthor Commented:
Yes the row header is visible but it does not work.
0
 
rkanabusAuthor Commented:
I knew that it was something simple.

instead of
 
Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(row.Index).Cells(0)

Open in new window


The solution is as follows:

 
DataGridView1.CurrentCell = DataGridView1.Item(column, row)

Open in new window


Then it works fine.

0
 
rkanabusAuthor Commented:
I just find it out.
0

Featured Post

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.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now