Results 1 to 2 of 2

Thread: How to read data from GridView?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009

    Question How to read data from GridView?

    Okay, I have a listview (gridview) with ten columns that is bound to a dataset. The dataset is populated by a query.

    I have it working so that I can select and display the data I want. Now, when the user double-clicks on a row, I want to grab the last column (contains the database key for that row) and use that to query additional data from children tables.

    I grab the mouse click fine and determine what row is being looked at.

    private void lvwSrch_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        int ndx = lvwSrch.SelectedIndex;
    What I simply CANNOT figure out how to do is access the data contained in the last column. I don't want to change it (this is a read-only app, a browser), I just want to get the key value for the selected row.

    Whether I get it through the dataset or the gridview doesn't matter to me... I just want to get the data. Any ideas how I can do this?

  2. #2
    Join Date
    Aug 2009

    Re: How to read data from GridView?

    Do you know the column name? if so, you can do the following (convert my VB.net to your C# of course)

    Dim TopicsDRV As DataRowView = lstTopics.SelectedItem
                    TopicID = TopicsDRV.Item("Topic_ID")
    This is applied to a listbox, but I'd think it should work the exact same for gridviews. What it does is grab the selected row, and then the "DRV.ITEM" pulls the value from that selected column.

    I am of course not a real hardcore developer so this may not work for you, but it works for listboxes as I'm using that exact code.

    Edit: I've tested it with Listviews and it works the exact same way. In addition, if you know the column you want to get data out of, you can substitute it's index in place of the column name, so for example:

    Dim CellContents as String
              Dim DataRow as DataRowView = ListView.SelectedItem
              CellContents = DataRow.Item(3)
    Last edited by evanrich; Nov 18th, 2010 at 07:00 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width