Solved

Selecting rows in a Datagrid

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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

19 Experts available now in Live!

Get 1:1 Help Now