DataTable, BindingSource and DataGridView

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric B.

    DataTable, BindingSource and DataGridView

    I could use a little clarification on using a BindingSource with my
    DataTable. As I understand it, the BindingSource sits between my data source
    (a DataTable) and DataGridView and any changes made to it is reflected in
    the other two?

    Now if that is so, how should I access the elements of my DataTable? I need
    to make decisions on what Rows to remove based on comparing the values of
    the elements. Should I access the individual elements via the DataTable,
    DataGridView cell values, or am I missing a member in my BindingSource
    object that allows me to retrieve and/or modify individual element values?

    TIA

    Eric B.

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: DataTable, BindingSource and DataGridView

    Eric,

    The BindingSource class was introduced because people were used to
    having the notion of a "current" record combined ^with^ the data set.

    You can access the current values of the "row" in the BindingSource
    through the indexer (the same way you would with a DataRow).

    If you need to cycle through the rows, you can use the MoveFirst,
    MoveNext, MoveLast, MovePrevious methods to navigate through the data.

    If the possibility of the type of the underlying data source might
    change, from a design standpoint, it would be better to work with the
    BindingSource, since that is abstracting the underlying data type.

    However, if the underlying data source type is "baked", meaning it will
    not change, then work with the data set.

    I will typically construct my own DataView when working with a DataTable
    and I need to perform specific sorting or filtering. If I don't have a need
    for that, then I access the DataSet directly.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Eric B." <bigbird@sesame street.comwrote in message
    news:E9171628-61B4-4A90-8110-31197A541756@mi crosoft.com...
    >I could use a little clarification on using a BindingSource with my
    >DataTable. As I understand it, the BindingSource sits between my data
    >source (a DataTable) and DataGridView and any changes made to it is
    >reflected in the other two?
    >
    Now if that is so, how should I access the elements of my DataTable? I
    need to make decisions on what Rows to remove based on comparing the
    values of the elements. Should I access the individual elements via the
    DataTable, DataGridView cell values, or am I missing a member in my
    BindingSource object that allows me to retrieve and/or modify individual
    element values?
    >
    TIA
    >
    Eric B.

    Comment

    • Eric B.

      #3
      Re: DataTable, BindingSource and DataGridView

      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c omwrote in
      message news:9BDBB790-E191-4580-AA3D-FB45815D905D@mi crosoft.com...
      Eric,
      >
      The BindingSource class was introduced because people were used to
      having the notion of a "current" record combined ^with^ the data set.
      >
      You can access the current values of the "row" in the BindingSource
      through the indexer (the same way you would with a DataRow).
      >
      If you need to cycle through the rows, you can use the MoveFirst,
      MoveNext, MoveLast, MovePrevious methods to navigate through the data.
      >
      If the possibility of the type of the underlying data source might
      change, from a design standpoint, it would be better to work with the
      BindingSource, since that is abstracting the underlying data type.
      >
      However, if the underlying data source type is "baked", meaning it will
      not change, then work with the data set.
      >
      I will typically construct my own DataView when working with a
      DataTable and I need to perform specific sorting or filtering. If I don't
      have a need for that, then I access the DataSet directly.
      >
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >
      "Eric B." <bigbird@sesame street.comwrote in message
      news:E9171628-61B4-4A90-8110-31197A541756@mi crosoft.com...
      >>I could use a little clarification on using a BindingSource with my
      >>DataTable. As I understand it, the BindingSource sits between my data
      >>source (a DataTable) and DataGridView and any changes made to it is
      >>reflected in the other two?
      >>
      >Now if that is so, how should I access the elements of my DataTable? I
      >need to make decisions on what Rows to remove based on comparing the
      >values of the elements. Should I access the individual elements via the
      >DataTable, DataGridView cell values, or am I missing a member in my
      >BindingSourc e object that allows me to retrieve and/or modify individual
      >element values?
      >>
      >TIA
      >>
      >Eric B.
      Thank you very much for the explanation. :D

      Eric B.

      Comment

      Working...