Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Select a ROW IN DATAGRID BY CLICK ON ANY COLUMN

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
bsheikh
Asked:
bsheikh
  • 3
  • 2
1 Solution
 
manchCommented:

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
 
cubixSoftwareCommented:
Hi

In the CurrentCellChanged event add

datagrid1.Select(datagrid1.CurrentRowIndex)



HTH
0
 
cubixSoftwareCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
bsheikhAuthor Commented:
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
 
bsheikhAuthor Commented:
one more thing thing to clear will this methong select multiple rows   as to move data ?
0
 
cubixSoftwareCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now