Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb.net datagrid view row header selection

Posted on 2011-02-24
7
Medium Priority
?
1,358 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
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!

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

722 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