Solved

Select a ROW IN DATAGRID  BY CLICK ON ANY COLUMN

Posted on 2006-06-21
6
208 Views
Last Modified: 2010-04-23
Hi Experts,

i am  using VB.NET 2003.
need to select a row an entire row when ever user clicks any of the column in that row.

regards,
smb
0
Comment
Question by:bsheikh
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:manch
ID: 16950880

Write the code on the DataGrid1 Click Event :

    Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click

        Dim picnt As Integer

        picnt = DataGrid1.CurrentRowIndex

        With DataGrid1
            .Select(picnt)
        End With

    End Sub
0
 
LVL 6

Expert Comment

by:cubixSoftware
ID: 16950896
Hi

In the CurrentCellChanged event add

datagrid1.Select(datagrid1.CurrentRowIndex)



HTH
0
 
LVL 6

Expert Comment

by:cubixSoftware
ID: 16950913
You need to be careful with the DataGrid click event as a datagrid is made up of columns such as Textbox and Checkbox and these controls will capture the click event, not the datagrid itself.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:bsheikh
ID: 16950964
cubix, your suggestion is working except 1 thing

lets say i have 5 columns . and i clicked column 3
it is highlighting  the entire row but the cell/column which i clicked is highlighted but not like the entier row . its like if i edit some thing ?


regards,
smb
0
 

Author Comment

by:bsheikh
ID: 16951000
one more thing thing to clear will this methong select multiple rows   as to move data ?
0
 
LVL 6

Accepted Solution

by:
cubixSoftware earned 60 total points
ID: 16951098
With regards multiple rows, there is no collection of SelectedRows like we have within a listview or listbox. To overcome this I created my own datagrid that held its own collection of RowsSelected that I could access.

If you don't want to do this then this code should work, just be aware it loops through all the rows within the grid  :(

dim i as integer
for i = 0 to datagrid1.rows.count -1
    if datagrid1.isselected(i) = true then
        ' do something for the selected row
    end if
next


With regards the other issue of highlighting then I have never been able to resolve it, but as the users have never complained I put it to the bottom of my to do list !
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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