locked
DataView question RRS feed

  • Question

  • Based on a DataSet of 30 rows, how do I apply a DataView on that dataset to return the first 10 rows?  Then apply a dataview to return rows 11-20, then 21-30?  I need this as a single dataview so I can place the dataview into the datagrid source.  Any help would be appreciated!
    Tuesday, October 11, 2005 5:38 PM

Answers

  • Sure.

    Since I was on a project with a few other people, the code was confusing, and still is a little.  However, I will post what I did to get it working.

    We are taking XML data and placing it into a dataset.  In order to take that dataset and place the data into a datagrid, we made a dataview and bound the dataview to the datagrid like so:

    Dim ds As New DataSet
    Dim dv As New DataView
    ds = vService.GetInfo(vFile)     'This gets the XML data from a web service
    dv = ds.Tables("Step")              'This sets the dataview to the dataset table "Step"

    'The dataview can show specified rows by applying a filter.  In the XML file I am pulling data '    from, there is a tag called "Line".  "Line" is used to count the number of rows the XML file
    '    has.  I didn't realize I could use operators other than "=" and "AND" within the RowFilter
    '    string.  However, after trying other operators, I found that I could use "Line < 10" to
    '    retrieve all Line elements that have a value less than 10.
    dv.RowFilter = "Line < 10"
    ds = Nothing

    'The datagrid uses the dataview which points to the filtered data
    Datagrid.Source = dv.DefaultView


    This is a rough idea of what I did.  All I needed to do was change the datagrid source to a dataview instead of a dataset so I could apply a row filter.  Once the change was made to a dataview, I applied a row filter based on my XML tag "Line" which counted the total number of rows within the XML file itself.  The filter is saying, "Give me all the Line numbers less than 10."  The dataview then points to the data applied by the filter.  Then I display the filtered data in a datagrid.

    Hopefully this made sense.  ;-)

    Mike
    Wednesday, October 12, 2005 2:18 PM

All replies

  • Figured it out....
    Tuesday, October 11, 2005 6:28 PM
  • Would you mind posting your solution? That way, others can benefit from it...
    Tuesday, October 11, 2005 7:17 PM
  • Sure.

    Since I was on a project with a few other people, the code was confusing, and still is a little.  However, I will post what I did to get it working.

    We are taking XML data and placing it into a dataset.  In order to take that dataset and place the data into a datagrid, we made a dataview and bound the dataview to the datagrid like so:

    Dim ds As New DataSet
    Dim dv As New DataView
    ds = vService.GetInfo(vFile)     'This gets the XML data from a web service
    dv = ds.Tables("Step")              'This sets the dataview to the dataset table "Step"

    'The dataview can show specified rows by applying a filter.  In the XML file I am pulling data '    from, there is a tag called "Line".  "Line" is used to count the number of rows the XML file
    '    has.  I didn't realize I could use operators other than "=" and "AND" within the RowFilter
    '    string.  However, after trying other operators, I found that I could use "Line < 10" to
    '    retrieve all Line elements that have a value less than 10.
    dv.RowFilter = "Line < 10"
    ds = Nothing

    'The datagrid uses the dataview which points to the filtered data
    Datagrid.Source = dv.DefaultView


    This is a rough idea of what I did.  All I needed to do was change the datagrid source to a dataview instead of a dataset so I could apply a row filter.  Once the change was made to a dataview, I applied a row filter based on my XML tag "Line" which counted the total number of rows within the XML file itself.  The filter is saying, "Give me all the Line numbers less than 10."  The dataview then points to the data applied by the filter.  Then I display the filtered data in a datagrid.

    Hopefully this made sense.  ;-)

    Mike
    Wednesday, October 12, 2005 2:18 PM