Solved

Select a ROW IN DATAGRID  BY CLICK ON ANY COLUMN

Posted on 2006-06-21
6
206 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
Comment Utility

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
Comment Utility
Hi

In the CurrentCellChanged event add

datagrid1.Select(datagrid1.CurrentRowIndex)



HTH
0
 
LVL 6

Expert Comment

by:cubixSoftware
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:bsheikh
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now