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. save datagrid

save datagrid

Scheduled Pinned Locked Moved C#
xmlquestion
7 Posts 2 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.
  • B Offline
    B Offline
    bertcox
    wrote on last edited by
    #1

    How come this doesn't work? He doesn't save the data you edit in the datagrid :confused: Thx in advance! private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { //get the node out of the xml-file string pad = "//school[@naam='" + comboBox1.SelectedItem.ToString() + "']"; XmlDocument xml = new XmlDocument(); xml.Load(@"c:\nodes.xml"); XmlNodeList contactNodes = xml.SelectNodes(pad); string box = contactNodes.Item(0).OuterXml; //write the node to a new file so it can be loaded into a dataset xml.LoadXml(box); XmlTextWriter xmltw = new XmlTextWriter(@"c:\testnodes.xml",new UTF8Encoding(false)); xml.WriteTo(xmltw); xmltw.Close(); DataSet ds = new DataSet(); ds.ReadXml(@"c:\testnodes.xml"); dataGrid1.DataSource = ds; dataGrid1.DataMember = "school"; } private void button1_Click(object sender, System.EventArgs e) { ds.WriteXml(@"c:\testnodes.xml"); }

    R 1 Reply Last reply
    0
    • B bertcox

      How come this doesn't work? He doesn't save the data you edit in the datagrid :confused: Thx in advance! private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { //get the node out of the xml-file string pad = "//school[@naam='" + comboBox1.SelectedItem.ToString() + "']"; XmlDocument xml = new XmlDocument(); xml.Load(@"c:\nodes.xml"); XmlNodeList contactNodes = xml.SelectNodes(pad); string box = contactNodes.Item(0).OuterXml; //write the node to a new file so it can be loaded into a dataset xml.LoadXml(box); XmlTextWriter xmltw = new XmlTextWriter(@"c:\testnodes.xml",new UTF8Encoding(false)); xml.WriteTo(xmltw); xmltw.Close(); DataSet ds = new DataSet(); ds.ReadXml(@"c:\testnodes.xml"); dataGrid1.DataSource = ds; dataGrid1.DataMember = "school"; } private void button1_Click(object sender, System.EventArgs e) { ds.WriteXml(@"c:\testnodes.xml"); }

      R Offline
      R Offline
      rull
      wrote on last edited by
      #2

      Call dataGrid1.DataBind() function after setting DataSource property.

      B 1 Reply Last reply
      0
      • R rull

        Call dataGrid1.DataBind() function after setting DataSource property.

        B Offline
        B Offline
        bertcox
        wrote on last edited by
        #3

        it sais that function doesn't exist 'System.Windows.Forms.DataGrid' does not contain a definition for 'DataBind' DataBindings is in the list but i don't know how to use that anyway thx for your answer

        R 1 Reply Last reply
        0
        • B bertcox

          it sais that function doesn't exist 'System.Windows.Forms.DataGrid' does not contain a definition for 'DataBind' DataBindings is in the list but i don't know how to use that anyway thx for your answer

          R Offline
          R Offline
          rull
          wrote on last edited by
          #4

          Sorry DataBind is for Asp.Net datagrid DataSet ds = new DataSet(); ds.ReadXml(@"c:\testnodes.xml"); dataGrid1.SetDataBinding(ds, "school"); You can find it here

          B 1 Reply Last reply
          0
          • R rull

            Sorry DataBind is for Asp.Net datagrid DataSet ds = new DataSet(); ds.ReadXml(@"c:\testnodes.xml"); dataGrid1.SetDataBinding(ds, "school"); You can find it here

            B Offline
            B Offline
            bertcox
            wrote on last edited by
            #5

            thx! i tried it but it still doesn't save the data in the datagrid :~

            R 1 Reply Last reply
            0
            • B bertcox

              thx! i tried it but it still doesn't save the data in the datagrid :~

              R Offline
              R Offline
              rull
              wrote on last edited by
              #6

              In your code you always write testnodes.xml file getting info from nodes.xml on comboBox1_SelectedIndexChanged. So you read data from one file, select, and than write to another file?(button1_Click).

              B 1 Reply Last reply
              0
              • R rull

                In your code you always write testnodes.xml file getting info from nodes.xml on comboBox1_SelectedIndexChanged. So you read data from one file, select, and than write to another file?(button1_Click).

                B Offline
                B Offline
                bertcox
                wrote on last edited by
                #7

                yes that's right, later on i will take the node from testnodes.xml en place it back into nodes.xml

                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