Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to create a class that can be used like a DataTable?

How to create a class that can be used like a DataTable?

Scheduled Pinned Locked Moved C#
csharptutorialquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael Sync
    wrote on last edited by
    #1

    I'm looking for the way to create a class that can be used like a DataTable. I just want to have the dynamic rows and columns (no need to have AcceptChanges or Rollback or etc).. but that class should be able to bind with DataGrid. Thanks.

    Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

    M 1 Reply Last reply
    0
    • M Michael Sync

      I'm looking for the way to create a class that can be used like a DataTable. I just want to have the dynamic rows and columns (no need to have AcceptChanges or Rollback or etc).. but that class should be able to bind with DataGrid. Thanks.

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

      M Offline
      M Offline
      Moim Hossain
      wrote on last edited by
      #2

      Michael Sync wrote:

      I'm looking for the way to create a class that can be used like a DataTable. I just want to have the dynamic rows and columns (no need to have AcceptChanges or Rollback or etc).. but that class should be able to bind with DataGrid.

      You can try inheriting the DataTable to write one...? But what's wrong using the DataTable directly... as long as you want to keep it binded with a DataSet..?

      Moim Hossain R&D Project Manager BlueCielo ECM Solutions BV

      M 1 Reply Last reply
      0
      • M Moim Hossain

        Michael Sync wrote:

        I'm looking for the way to create a class that can be used like a DataTable. I just want to have the dynamic rows and columns (no need to have AcceptChanges or Rollback or etc).. but that class should be able to bind with DataGrid.

        You can try inheriting the DataTable to write one...? But what's wrong using the DataTable directly... as long as you want to keep it binded with a DataSet..?

        Moim Hossain R&D Project Manager BlueCielo ECM Solutions BV

        M Offline
        M Offline
        Michael Sync
        wrote on last edited by
        #3

        Thanks. Actually, I'm using Prism (CompositeWPF) version 2 with multi-targeting feature. Once we crate a class, we have to think about how to use in both WPF and Silverlight. DataTable or DataSet or etc is not available in Silverlight. So, I'm thinking to create very small version of DataTable that we can add/remove the column with Columns name. And we want to bind it with DataGird.

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

        M 1 Reply Last reply
        0
        • M Michael Sync

          Thanks. Actually, I'm using Prism (CompositeWPF) version 2 with multi-targeting feature. Once we crate a class, we have to think about how to use in both WPF and Silverlight. DataTable or DataSet or etc is not available in Silverlight. So, I'm thinking to create very small version of DataTable that we can add/remove the column with Columns name. And we want to bind it with DataGird.

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

          M Offline
          M Offline
          Moim Hossain
          wrote on last edited by
          #4

          Michael Sync wrote:

          I'm thinking to create very small version of DataTable that we can add/remove the column with Columns name

          Well, in that case, you might need to write a simple and small version of DataTable for ur ViewModel. You can make use of reflector to get more idea about the .net implementation of DataTable. One suggestion though, if the binding is the only concern, you could actually define any .net enumerable properties ..I guess?

          Moim Hossain R&D Project Manager BlueCielo ECM Solutions BV

          M 1 Reply Last reply
          0
          • M Moim Hossain

            Michael Sync wrote:

            I'm thinking to create very small version of DataTable that we can add/remove the column with Columns name

            Well, in that case, you might need to write a simple and small version of DataTable for ur ViewModel. You can make use of reflector to get more idea about the .net implementation of DataTable. One suggestion though, if the binding is the only concern, you could actually define any .net enumerable properties ..I guess?

            Moim Hossain R&D Project Manager BlueCielo ECM Solutions BV

            M Offline
            M Offline
            Michael Sync
            wrote on last edited by
            #5

            Yes. I'm thinking to have a class like below. class MyDataRow{ } class MyDataColumn{ } class MyDataTable{ List Rows{} List Columns{} } but 1) I'm not sure whether how I can make my class as a binding class. eg. VM public MyDataTable MyData{ set{.. ....PropertyChanged(..).... } get{..} } 2. How can I know whether new column or row has been added to now?? E.g. MyDataTable mydata = new MyDataTable(); mydata.Columns.Add(new MyDataColumn() { Name = "A" }); mydata.Columns.Add(new MyDataColumn() { Name = "B" }); mydata.Columns.Add(new MyDataColumn() { Name = "C" }); Thanks in advance.

            N 1 Reply Last reply
            0
            • M Michael Sync

              Yes. I'm thinking to have a class like below. class MyDataRow{ } class MyDataColumn{ } class MyDataTable{ List Rows{} List Columns{} } but 1) I'm not sure whether how I can make my class as a binding class. eg. VM public MyDataTable MyData{ set{.. ....PropertyChanged(..).... } get{..} } 2. How can I know whether new column or row has been added to now?? E.g. MyDataTable mydata = new MyDataTable(); mydata.Columns.Add(new MyDataColumn() { Name = "A" }); mydata.Columns.Add(new MyDataColumn() { Name = "B" }); mydata.Columns.Add(new MyDataColumn() { Name = "C" }); Thanks in advance.

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              You may want to look here http://msdn.microsoft.com/en-us/library/ms752347.aspx[^] Couldn't your problem be solved by using a WebService or WCF to expose the necessary data?


              only two letters away from being an asset

              M 1 Reply Last reply
              0
              • N Not Active

                You may want to look here http://msdn.microsoft.com/en-us/library/ms752347.aspx[^] Couldn't your problem be solved by using a WebService or WCF to expose the necessary data?


                only two letters away from being an asset

                M Offline
                M Offline
                Michael Sync
                wrote on last edited by
                #7

                No. WCF team can give only the list of column that I need to show on the DataGird and the data that I need to populate to the DataGrid. Thanks.

                Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

                N 1 Reply Last reply
                0
                • M Michael Sync

                  No. WCF team can give only the list of column that I need to show on the DataGird and the data that I need to populate to the DataGrid. Thanks.

                  Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

                  N Offline
                  N Offline
                  Not Active
                  wrote on last edited by
                  #8

                  I'm sorry, am I missing something? You can get the data and the columns, isn't that what a DataTable defines also. You get the data in an XML format, or even a collection of some sort, and bind it to the grid. I'm just not seeing your problem I guess.


                  only two letters away from being an asset

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups