Get row in datagrid

Posted on 2006-04-22
Last Modified: 2010-04-23

I have a datagrid that is based on a dataset. I can access the data in code with the datagrid.item( row, column) function, but I have one problem : the user can select the order of the columns himself, so the columnnumber doesn't always have the same data. He can also sort the datagrid by clicking on the header.

So I would like to get the rownumber in the dataset that corresponds to the rownumber in the datagrid, so I can access data through a row:
  dim localrow as mydataset.myrow

  localrow = mydataset.myrow(..)
  string = localrow.field

No what I don't figure out is how to assign the correct row.  Can you help me ?
Question by:ACAE
    LVL 4

    Expert Comment


    you can use your Data's ID , since you are showing Datagrid it must have some ID associated to it, like product id which is unique for your datagrid, use that value to identify your row.

    Hope I am clear

    LVL 14

    Accepted Solution

    If you want the currently selected row:

        Dim cm As CurrencyManager = CType(dg.Parent.BindingContext(dg.DataSource, dg.DataMember), CurrencyManager) ' Where dg = your DataGrid

        ' Retrieve the default DataView of the DataGrid
        Dim dv As DataView = CType(cm.List, DataView)

       Dim localrow As DataRow = dv.Item(dg.CurrentRowIndex).Row


    Author Comment

    It seems to work fine, thx for your help !

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    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

    11 Experts available now in Live!

    Get 1:1 Help Now