Solved

vb.net datagrid view row header selection

Posted on 2011-02-24
7
1,332 Views
Last Modified: 2012-05-11
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
Comment
Question by:rkanabus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 34968663
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
 

Author Comment

by:rkanabus
ID: 34968737
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
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 34968910
Can you post an image you want to achieve...
0
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.

 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 34968921
Also make sure that the dataGridView1.RowHeadersVisible is set to true

dataGridView1.RowHeadersVisible = True
0
 

Author Comment

by:rkanabus
ID: 34969165
Yes the row header is visible but it does not work.
0
 

Accepted Solution

by:
rkanabus earned 0 total points
ID: 34969335
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
 

Author Closing Comment

by:rkanabus
ID: 35163588
I just find it out.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

636 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