Solved

Selecting rows in a Datagrid

Posted on 2004-09-17
4
197 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

930 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

10 Experts available now in Live!

Get 1:1 Help Now