Gopher2011
Well-known member
I am trying to get my datagridview to display more than one row of data.
Every time I call the program it only writes the 1st line of data in the datagridview instead of adding it to a new row.
I have been looking on the forums for hours but combined with my inexperience I can not understand it.
The following code is in a loop and it reads an xml file each time. The goal is to put the xml data from each file into a new row in the table.
Every time I call the program it only writes the 1st line of data in the datagridview instead of adding it to a new row.
I have been looking on the forums for hours but combined with my inexperience I can not understand it.
The following code is in a loop and it reads an xml file each time. The goal is to put the xml data from each file into a new row in the table.
VB.NET:
[COLOR=#00008B]Public[/COLOR][COLOR=#00008B]Sub[/COLOR][COLOR=#000000] ReadData[/COLOR][COLOR=#000000]([/COLOR][COLOR=#00008B]ByVal[/COLOR][COLOR=#000000] filename [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#00008B]String[/COLOR][COLOR=#000000],[/COLOR][COLOR=#00008B]ByVal[/COLOR][COLOR=#000000] file [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#00008B]String[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]Try[/COLOR][COLOR=#000000]
DS[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]ReadXml[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]filename[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
DS[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Tables[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Add[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"MyTable"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]With[/COLOR][COLOR=#000000] DS[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Tables[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"MyTable"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Columns[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Add[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"Title 1"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Columns[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Add[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"Title 2"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Columns[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Add[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"Title 3"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Columns[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Add[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"Title 4"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Columns[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Add[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"Title 5"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Columns[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Add[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"Title 6"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#00008B]With[/COLOR][COLOR=#000000]
Using reader [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#00008B]New[/COLOR][COLOR=#000000] StreamReader[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]filename[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]Dim[/COLOR][COLOR=#000000] line [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#00008B]String[/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] reader[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]ReadToEnd[/COLOR][COLOR=#000000]()[/COLOR][COLOR=#000000]
rtb_Subsidary[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]AppendText[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]file [/COLOR][COLOR=#000000]&[/COLOR][COLOR=#000000] vbCrLf[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
DS[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Tables[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"MyTable"[/COLOR][COLOR=#000000]).[/COLOR][COLOR=#000000]Rows[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Add[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000]file[/COLOR][COLOR=#000000],[/COLOR][COLOR=#800000]"test 1"[/COLOR][COLOR=#000000],[/COLOR][COLOR=#800000]"test 2"[/COLOR][COLOR=#000000],[/COLOR][COLOR=#800000]"test 3"[/COLOR][COLOR=#000000],[/COLOR][COLOR=#800000]"test 4"[/COLOR][COLOR=#000000],[/COLOR][COLOR=#800000]"test 5"[/COLOR][COLOR=#000000],[/COLOR][COLOR=#800000]"test 6"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#000000] Using
[/COLOR][COLOR=#00008B]With[/COLOR][COLOR=#000000] dgv_Lic
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]DataSource [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] DS[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Tables[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]"MyTable"[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#00008B]ReadOnly[/COLOR][COLOR=#000000]=[/COLOR][COLOR=#800000]True[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]ScrollBars [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] ScrollBars[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Vertical
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]AutoSizeColumnsMode [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] DataGridViewAutoSizeColumnsMode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Fill
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]AutoResizeColumns[/COLOR][COLOR=#000000]()[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]RowHeadersVisible [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#800000]False[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]For[/COLOR][COLOR=#00008B]Each[/COLOR][COLOR=#000000] col [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#000000] DataGridViewColumn [/COLOR][COLOR=#00008B]In[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Columns
col[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]SortMode [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] DataGridViewColumnSortMode[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]NotSortable
[/COLOR][COLOR=#00008B]Next[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#00008B]With[/COLOR][COLOR=#000000]
[/COLOR][COLOR=#000000]...[/COLOR][COLOR=#00008B]end[/COLOR][COLOR=#000000] code[/COLOR]