Solved

Selecting rows in a Datagrid

Posted on 2004-09-17
4
210 Views
Last Modified: 2010-04-23
I'm using a Datagrid with a column to select the row. How do I detect that the row was selected? How do I get the data from the columns in the selected row?
0
Comment
Question by:Rick4848
4 Comments
 
LVL 27

Accepted Solution

by:
planocz earned 63 total points
ID: 12086230
0
 
LVL 8

Assisted Solution

by:bramsquad
bramsquad earned 62 total points
ID: 12104807
the question above is if you choose to select the whole row instead of a cell....suppose id know, i answered it :)

you need to use the CurrentCellChanged event handler to see if a new row was selected

    Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
        'do stuff here, and heres how you tell what row and column you have selected
        Dim row As Integer = DataGrid1.CurrentCell.RowNumber
        Dim col As Integer = DataGrid1.CurrentCell.ColumnNumber
    End Sub

if you want data from your datagrid, heres how you go about it (i use this in my double click event procedure)

    Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
        'use this for err handling
        If DataGrid1.CurrentCell.RowNumber = 0 And DataGrid1.CurrentCell.ColumnNumber = 0 Then
            Exit Sub
        Else
            Me.cbosearch.SelectedIndex = DataGrid1.CurrentCell.ColumnNumber
            Me.txtSearch.Text = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, DataGrid1.CurrentCell.ColumnNumber)
        End If
    End Sub

this line

Me.txtSearch.Text = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, DataGrid1.CurrentCell.ColumnNumber)

should answer your second question.  you need to use the CurrentCell property with both of your problems.

~b
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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