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 do I add row data directly to a DataGrid Class?

How do I add row data directly to a DataGrid Class?

Scheduled Pinned Locked Moved C#
helptutorialquestiondata-structures
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.
  • X Offline
    X Offline
    Xarzu
    wrote on last edited by
    #1

    How do I add row data directly to a DataGrid Class? I am using a free opensource class from a company that I will not name (even if it is RadiantQ) that I like a lot. It has this cool MuttiColumnTreeList control that is a combination of a tree control and a datagrid. It comes with an example code that you can look at and everything. It is pretty cool. It is inherited from the DataGrid class. The problem is that I am kind of new to databinding on this level and so I would like to just go ahead and write some code that forces the data that I have gathered from another class into the control. So I looked online for how to do that for a DataGrid class and the information is not easily available. Can anyone help?

    P E 2 Replies Last reply
    0
    • X Xarzu

      How do I add row data directly to a DataGrid Class? I am using a free opensource class from a company that I will not name (even if it is RadiantQ) that I like a lot. It has this cool MuttiColumnTreeList control that is a combination of a tree control and a datagrid. It comes with an example code that you can look at and everything. It is pretty cool. It is inherited from the DataGrid class. The problem is that I am kind of new to databinding on this level and so I would like to just go ahead and write some code that forces the data that I have gathered from another class into the control. So I looked online for how to do that for a DataGrid class and the information is not easily available. Can anyone help?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Which DataGrid? Are you talking about the XAML based version? If so, please take your questions to the Silverlight/WPF forum as they are more appropriate there.

      Forgive your enemies - it messes with their heads

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      X 1 Reply Last reply
      0
      • X Xarzu

        How do I add row data directly to a DataGrid Class? I am using a free opensource class from a company that I will not name (even if it is RadiantQ) that I like a lot. It has this cool MuttiColumnTreeList control that is a combination of a tree control and a datagrid. It comes with an example code that you can look at and everything. It is pretty cool. It is inherited from the DataGrid class. The problem is that I am kind of new to databinding on this level and so I would like to just go ahead and write some code that forces the data that I have gathered from another class into the control. So I looked online for how to do that for a DataGrid class and the information is not easily available. Can anyone help?

        E Offline
        E Offline
        ebukaegonu2
        wrote on last edited by
        #3

        Well first Which Datagrid are you referring to? you can try this in the "Click Event" for your binding. //Note this Will work if you are using Microsoft Enterprise Library //else, look at the Code and try to Convert it to one Using ADO //new DAL SUNIG dal = new SUNIG(); string msg = ""; //declare a new dataset DataSet ds = new DataSet(); //pass the data to to the dal, and fetch the data you want to Bind to the Grid. /*Note: your Stored Procedure Must have to Fetch all the Data from the Table you want to Bind with/without a criteria eg: ds = dal.fetchYOURDATA(ref msg); // do your Validation and Exception CHecking //eg if (msg != "") { MessageBox.Show("Put your Exception Message Here" + msg); return } //do your databinding here DataGridView1.Dataset = ds; DataGridview1.DataBind(); Hope it Helps!! :)

        X 1 Reply Last reply
        0
        • E ebukaegonu2

          Well first Which Datagrid are you referring to? you can try this in the "Click Event" for your binding. //Note this Will work if you are using Microsoft Enterprise Library //else, look at the Code and try to Convert it to one Using ADO //new DAL SUNIG dal = new SUNIG(); string msg = ""; //declare a new dataset DataSet ds = new DataSet(); //pass the data to to the dal, and fetch the data you want to Bind to the Grid. /*Note: your Stored Procedure Must have to Fetch all the Data from the Table you want to Bind with/without a criteria eg: ds = dal.fetchYOURDATA(ref msg); // do your Validation and Exception CHecking //eg if (msg != "") { MessageBox.Show("Put your Exception Message Here" + msg); return } //do your databinding here DataGridView1.Dataset = ds; DataGridview1.DataBind(); Hope it Helps!! :)

          X Offline
          X Offline
          Xarzu
          wrote on last edited by
          #4

          It seems that once the databinding is done, and if you change the data you have to rebind to the control. This is what was giving me difficulty before. So what I have to do is run some command like this: this.mutlicoolgridview.ItemsSource = null; this.mutlicoolgridview.ItemsSource = SampleData.GetSampleDataNew(); The problem I am having now is this. After running his command about one thousand times, I actually run out of memory. I think that doing this: this.mutlicoolgridview.ItemsSource = null; is not such a good idea. Is there a better command to do to free up the memory?

          1 Reply Last reply
          0
          • P Pete OHanlon

            Which DataGrid? Are you talking about the XAML based version? If so, please take your questions to the Silverlight/WPF forum as they are more appropriate there.

            Forgive your enemies - it messes with their heads

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            X Offline
            X Offline
            Xarzu
            wrote on last edited by
            #5

            It seems that once the databinding is done, and if you change the data you have to rebind to the control. This is what was giving me difficulty before. So what I have to do is run some command like this: this.mutlicoolgridview.ItemsSource = null; this.mutlicoolgridview.ItemsSource = SampleData.GetSampleDataNew(); The problem I am having now is this. After running his command about one thousand times, I actually run out of memory. I think that doing this: this.mutlicoolgridview.ItemsSource = null; is not such a good idea. Is there a better command to do to free up the memory?

            P 1 Reply Last reply
            0
            • X Xarzu

              It seems that once the databinding is done, and if you change the data you have to rebind to the control. This is what was giving me difficulty before. So what I have to do is run some command like this: this.mutlicoolgridview.ItemsSource = null; this.mutlicoolgridview.ItemsSource = SampleData.GetSampleDataNew(); The problem I am having now is this. After running his command about one thousand times, I actually run out of memory. I think that doing this: this.mutlicoolgridview.ItemsSource = null; is not such a good idea. Is there a better command to do to free up the memory?

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Xarzu wrote:

              It seems that once the databinding is done, and if you change the data you have to rebind to the control.

              No you don't. You're doing it wrong. With XAML binding, you bind to a collection that implements ICollectionChanged (such as an ObservableCollection), then you update the original collection - you don't create a new one, you don't rebind to it.

              Forgive your enemies - it messes with their heads

              "Mind bleach! Send me mind bleach!" - Nagy Vilmos

              My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

              X 1 Reply Last reply
              0
              • P Pete OHanlon

                Xarzu wrote:

                It seems that once the databinding is done, and if you change the data you have to rebind to the control.

                No you don't. You're doing it wrong. With XAML binding, you bind to a collection that implements ICollectionChanged (such as an ObservableCollection), then you update the original collection - you don't create a new one, you don't rebind to it.

                Forgive your enemies - it messes with their heads

                "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                X Offline
                X Offline
                Xarzu
                wrote on last edited by
                #7

                Thank you, Pete. I will change and test my code. Is there some way I can force a ICollectionChanged message?

                P 1 Reply Last reply
                0
                • X Xarzu

                  Thank you, Pete. I will change and test my code. Is there some way I can force a ICollectionChanged message?

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  If you're using an ObservableCollection, you don't have to. It raises the CollectionChanged events for you when you add or remove items.

                  Forgive your enemies - it messes with their heads

                  "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                  My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                  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