Solved

Selecting rows in a Datagrid

Posted on 2004-09-17
4
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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