all groups > dotnet windows forms databinding > december 2006 >
As I posted in the other ng where you posted this question, try DataSet1.Reset() Robin S. ---------------------------------------- [quoted text, click to view] "David Mayerovitch" <davmay@sympatico.ca> wrote in message news:%23Nmt2fKLHHA.1424@TK2MSFTNGP04.phx.gbl... > As an exercise in learning Visual Basic 2005, I am putting together a > simple > XML editor. > > I place on the form the objects DataGridView1 and DataSet1. > > ' Read an XML file into DataSet1: > DataSet1.ReadXml("BIRDS.XML") > > ' Bind the DataGridView to the DataSet: > DataGridView1.DataSource = DataSet1 > > ' Having determined that the TableName of the > ' DataTable I am interested in is "bird", > ' make this the DataMember of the DataGridView: > > DataGridView1.DataMember = "bird" > > ' Set up autogeneration of columns: > DataGridView1.AutoGenerateColumns = True > > And now the contents of the file appear in the grid for viewing and > editing. > OK so far. > > But now I want to load in a new file. When I load "MUSICIANS.XML", > with its > DataMember "musician", the existing data from "BIRDS.XML" is not > overwritten. It either remains as it is within the grid and the > MUSICIANS > data fails to appear, or, depending on the structure of the new file, > the > new data may be appended to the existing data. The number of columns > and > their headings remain what they were instead of reflecting the > structure of > the new file. Sometimes no data appears under these headings after the > loading of the new file. > > Obviously I need some way of re-initializing the DataSet or the > DataGridView > or both before loading a new file. I have been able to do this only by > re-instantiating the DataSet on each pass: > > Dim DataSet1 As New DataSet > > This gets rid of all previous data and I can load different files in > succession. But it's not a good solution because instantiating the > DataSet > within a Sub means, I assume, that it won't be visible to other > routines > that I'll need for saving data back to a file. And it's probably bad > for > other reasons too. > > I tried setting > DataGridView1.DataSource = Nothing > > but this didn't work. > > Neither did > DataSet1.Clear() > > So can anyone tell me how to re-initialize the DataSet and/or the > DataGridView so that I can load new files cleanly? I couldn't find > anything > in the documentation. (If there is an explanation somewhere, please > point me > to it.) > > Thanks. > David > >
As an exercise in learning Visual Basic 2005, I am putting together a simple XML editor. I place on the form the objects DataGridView1 and DataSet1. ' Read an XML file into DataSet1: DataSet1.ReadXml("BIRDS.XML") ' Bind the DataGridView to the DataSet: DataGridView1.DataSource = DataSet1 ' Having determined that the TableName of the ' DataTable I am interested in is "bird", ' make this the DataMember of the DataGridView: DataGridView1.DataMember = "bird" ' Set up autogeneration of columns: DataGridView1.AutoGenerateColumns = True And now the contents of the file appear in the grid for viewing and editing. OK so far. But now I want to load in a new file. When I load "MUSICIANS.XML", with its DataMember "musician", the existing data from "BIRDS.XML" is not overwritten. It either remains as it is within the grid and the MUSICIANS data fails to appear, or, depending on the structure of the new file, the new data may be appended to the existing data. The number of columns and their headings remain what they were instead of reflecting the structure of the new file. Sometimes no data appears under these headings after the loading of the new file. Obviously I need some way of re-initializing the DataSet or the DataGridView or both before loading a new file. I have been able to do this only by re-instantiating the DataSet on each pass: Dim DataSet1 As New DataSet This gets rid of all previous data and I can load different files in succession. But it's not a good solution because instantiating the DataSet within a Sub means, I assume, that it won't be visible to other routines that I'll need for saving data back to a file. And it's probably bad for other reasons too. I tried setting DataGridView1.DataSource = Nothing but this didn't work. Neither did DataSet1.Clear() So can anyone tell me how to re-initialize the DataSet and/or the DataGridView so that I can load new files cleanly? I couldn't find anything in the documentation. (If there is an explanation somewhere, please point me to it.) Thanks. David
Thanks, Robin - That's just what I needed! David [quoted text, click to view] "RobinS" <RobinS@NoSpam.yah.none> wrote in message news:Eu-dnfO4WbDN9ArYnZ2dnUVZ_sSmnZ2d@comcast.com... > As I posted in the other ng where you posted this question, > try DataSet1.Reset() > > Robin S. > ---------------------------------------- > "David Mayerovitch" <davmay@sympatico.ca> wrote in message > news:%23Nmt2fKLHHA.1424@TK2MSFTNGP04.phx.gbl... >> As an exercise in learning Visual Basic 2005, I am putting together a >> simple >> XML editor. >> >> I place on the form the objects DataGridView1 and DataSet1. >> >> ' Read an XML file into DataSet1: >> DataSet1.ReadXml("BIRDS.XML") >> >> ' Bind the DataGridView to the DataSet: >> DataGridView1.DataSource = DataSet1 >> >> ' Having determined that the TableName of the >> ' DataTable I am interested in is "bird", >> ' make this the DataMember of the DataGridView: >> >> DataGridView1.DataMember = "bird" >> >> ' Set up autogeneration of columns: >> DataGridView1.AutoGenerateColumns = True >> >> And now the contents of the file appear in the grid for viewing and >> editing. >> OK so far. >> >> But now I want to load in a new file. When I load "MUSICIANS.XML", with >> its >> DataMember "musician", the existing data from "BIRDS.XML" is not >> overwritten. It either remains as it is within the grid and the MUSICIANS >> data fails to appear, or, depending on the structure of the new file, the >> new data may be appended to the existing data. The number of columns and >> their headings remain what they were instead of reflecting the structure >> of >> the new file. Sometimes no data appears under these headings after the >> loading of the new file. >> >> Obviously I need some way of re-initializing the DataSet or the >> DataGridView >> or both before loading a new file. I have been able to do this only by >> re-instantiating the DataSet on each pass: >> >> Dim DataSet1 As New DataSet >> >> This gets rid of all previous data and I can load different files in >> succession. But it's not a good solution because instantiating the >> DataSet >> within a Sub means, I assume, that it won't be visible to other routines >> that I'll need for saving data back to a file. And it's probably bad for >> other reasons too. >> >> I tried setting >> DataGridView1.DataSource = Nothing >> >> but this didn't work. >> >> Neither did >> DataSet1.Clear() >> >> So can anyone tell me how to re-initialize the DataSet and/or the >> DataGridView so that I can load new files cleanly? I couldn't find >> anything >> in the documentation. (If there is an explanation somewhere, please point >> me >> to it.) >> >> Thanks. >> David >> >> > >
You're welcome; I'm glad it helped! Robin S. ---------------------- [quoted text, click to view] "David Mayerovitch" <davmay@sympatico.ca> wrote in message news:eiRh1YQLHHA.3564@TK2MSFTNGP02.phx.gbl... > Thanks, Robin - That's just what I needed! > David > > "RobinS" <RobinS@NoSpam.yah.none> wrote in message > news:Eu-dnfO4WbDN9ArYnZ2dnUVZ_sSmnZ2d@comcast.com... >> As I posted in the other ng where you posted this question, >> try DataSet1.Reset() >> >> Robin S. >> ---------------------------------------- >> "David Mayerovitch" <davmay@sympatico.ca> wrote in message >> news:%23Nmt2fKLHHA.1424@TK2MSFTNGP04.phx.gbl... >>> As an exercise in learning Visual Basic 2005, I am putting together >>> a simple >>> XML editor. >>> >>> I place on the form the objects DataGridView1 and DataSet1. >>> >>> ' Read an XML file into DataSet1: >>> DataSet1.ReadXml("BIRDS.XML") >>> >>> ' Bind the DataGridView to the DataSet: >>> DataGridView1.DataSource = DataSet1 >>> >>> ' Having determined that the TableName of the >>> ' DataTable I am interested in is "bird", >>> ' make this the DataMember of the DataGridView: >>> >>> DataGridView1.DataMember = "bird" >>> >>> ' Set up autogeneration of columns: >>> DataGridView1.AutoGenerateColumns = True >>> >>> And now the contents of the file appear in the grid for viewing and >>> editing. >>> OK so far. >>> >>> But now I want to load in a new file. When I load "MUSICIANS.XML", >>> with its >>> DataMember "musician", the existing data from "BIRDS.XML" is not >>> overwritten. It either remains as it is within the grid and the >>> MUSICIANS >>> data fails to appear, or, depending on the structure of the new >>> file, the >>> new data may be appended to the existing data. The number of columns >>> and >>> their headings remain what they were instead of reflecting the >>> structure of >>> the new file. Sometimes no data appears under these headings after >>> the >>> loading of the new file. >>> >>> Obviously I need some way of re-initializing the DataSet or the >>> DataGridView >>> or both before loading a new file. I have been able to do this only >>> by >>> re-instantiating the DataSet on each pass: >>> >>> Dim DataSet1 As New DataSet >>> >>> This gets rid of all previous data and I can load different files in >>> succession. But it's not a good solution because instantiating the >>> DataSet >>> within a Sub means, I assume, that it won't be visible to other >>> routines >>> that I'll need for saving data back to a file. And it's probably bad >>> for >>> other reasons too. >>> >>> I tried setting >>> DataGridView1.DataSource = Nothing >>> >>> but this didn't work. >>> >>> Neither did >>> DataSet1.Clear() >>> >>> So can anyone tell me how to re-initialize the DataSet and/or the >>> DataGridView so that I can load new files cleanly? I couldn't find >>> anything >>> in the documentation. (If there is an explanation somewhere, please >>> point me >>> to it.) >>> >>> Thanks. >>> David >>> >>> >> >> > >
Don't see what you're looking for? Try a search.
|
|
|