Solved

vb.net datagrid view row header selection

Posted on 2011-02-24
7
1,270 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
  • 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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