Solved

vb.net datagrid view row header selection

Posted on 2011-02-24
7
1,279 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

821 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