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. Visual Basic
  4. Databinding, XML, DataGridView problem

Databinding, XML, DataGridView problem

Scheduled Pinned Locked Moved Visual Basic
csswpfwcfxmlhelp
5 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.
  • P Offline
    P Offline
    penguin5000
    wrote on last edited by
    #1

    Hi, I'm using VB2005 Express to create a small app which is intended to allow me to build up the contents of an XML file. I've got the DataGridView in place, and it is reading in and displaying the contents of an XML file. I've got a button on the form which allows me to insert a column in the DataGridView, but when I press 'Save' it writes an XML file, but it doesn't include the new column I've just entered in my grid. I suspect that it may be a binding problem, but I don't know how to code this part of the app. Any advice would be appreciated.

    C D 2 Replies Last reply
    0
    • P penguin5000

      Hi, I'm using VB2005 Express to create a small app which is intended to allow me to build up the contents of an XML file. I've got the DataGridView in place, and it is reading in and displaying the contents of an XML file. I've got a button on the form which allows me to insert a column in the DataGridView, but when I press 'Save' it writes an XML file, but it doesn't include the new column I've just entered in my grid. I suspect that it may be a binding problem, but I don't know how to code this part of the app. Any advice would be appreciated.

      C Offline
      C Offline
      ctlqt12
      wrote on last edited by
      #2

      You can try this : '=====Read and display xml file on DataGridView===== Dim ds as new DataSet ds.ReadXml("c:\YourFile.xml") dgv.DataSource = ds.Tables(0) '=====End===== '=====Create new column===== Dim col as new DataColumn("MyNewColumn",System.Type.GetType("System.String")) ds.Tables(0).Columns.Add(col) '=====End===== '=====Save xml file ds.WriteXml("c:\\YourFile.xml") '=====End=====

      1 Reply Last reply
      0
      • P penguin5000

        Hi, I'm using VB2005 Express to create a small app which is intended to allow me to build up the contents of an XML file. I've got the DataGridView in place, and it is reading in and displaying the contents of an XML file. I've got a button on the form which allows me to insert a column in the DataGridView, but when I press 'Save' it writes an XML file, but it doesn't include the new column I've just entered in my grid. I suspect that it may be a binding problem, but I don't know how to code this part of the app. Any advice would be appreciated.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        OK. This is a typical newbie misconception. The DataGridVIEW doesn't hold the data you're looking at. It mearly SHOWS it. The data is being held is a DataSet object, which is a collection of DataTables and DataRelation object. DataTables hold DataColumns and DataRows. If you added the column to the DataGridView, you just added a column that can be used to VIEW data, not hold it. You have to add the new column to the DataTable that will hold the data your adding. This will update the schema that's used to write the XML file.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        P 1 Reply Last reply
        0
        • D Dave Kreskowiak

          OK. This is a typical newbie misconception. The DataGridVIEW doesn't hold the data you're looking at. It mearly SHOWS it. The data is being held is a DataSet object, which is a collection of DataTables and DataRelation object. DataTables hold DataColumns and DataRows. If you added the column to the DataGridView, you just added a column that can be used to VIEW data, not hold it. You have to add the new column to the DataTable that will hold the data your adding. This will update the schema that's used to write the XML file.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          P Offline
          P Offline
          penguin5000
          wrote on last edited by
          #4

          Thanks for your reply. I am new-ish to it, and was aware that I was adding the column to my 'view'. I had already tried adding the column to my table, but it just didn't seem to work, which is why I assumed there was some sort of binding problem going on. If it isn't a binding problem, I must be doing something wrong. Am I right in thinking that if I read the XML file in, I've automatically got my dataset and tables to work with, and if I update my table in any way I choose (i.e. adding/deleting rows/columns), it is the same table in the exact same dataset that I write back to XML?

          D 1 Reply Last reply
          0
          • P penguin5000

            Thanks for your reply. I am new-ish to it, and was aware that I was adding the column to my 'view'. I had already tried adding the column to my table, but it just didn't seem to work, which is why I assumed there was some sort of binding problem going on. If it isn't a binding problem, I must be doing something wrong. Am I right in thinking that if I read the XML file in, I've automatically got my dataset and tables to work with, and if I update my table in any way I choose (i.e. adding/deleting rows/columns), it is the same table in the exact same dataset that I write back to XML?

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            penguin5000 wrote:

            I had already tried adding the column to my table, but it just didn't seem to work, which is why I assumed there was some sort of binding problem going on.

            If you want to see this change, then you either have to manually add the new column to the DGV, or just rebind the DGV to your datasource so it can regenerate the columns it needs to display the data.

            penguin5000 wrote:

            Am I right in thinking that if I read the XML file in, I've automatically got my dataset and tables to work with, and if I update my table in any way I choose (i.e. adding/deleting rows/columns), it is the same table in the exact same dataset that I write back to XML?

            Yes. This will overwrite the existing XML file with the new data and schema.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            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