cafferm
asked on
Reset Datagrid and Datatable
Hi....Help
I have a form in a windows app with a datagrid attached to it which gets its data from the datatable which i build through some XML data. Problem is when i want to go back into the form and change the data in the table it won't let me. I have tried reseting, clearing and others but hink i am missing something fairly basic.
Your help would be appreciated - The code i have is below
Sub datagrider()
Try
Dim DataTable As New Data.DataTable("FileConten ts")
Dim l As Integer
With DataTable.Columns
.Add("Template_id")
.Add("fleid")
.Add("Account Name")
End With
Dim newIt As ListViewItem
Dim nodelist As XmlNodeList = xmlDoc.SelectNodes("/deid/ deFile")
Dim node As XmlNode
l = -1
For Each node In nodelist
If node.SelectSingleNode("Tem plate_id") .InnerText = lblid.Text Then ' where lblid is selected detail on another form
l += 1
With DataTable.Rows
.Add(New Object() {})
.Item(l).Item(0) = node.SelectSingleNode("Tem plate_id") .InnerText
.Item(l).Item(1) = node.Attributes("fleid").I nnerText
.Item(l).Item(2) = node.SelectSingleNode("Acc ount_Name" ).InnerTex t
End With
DataTable.AcceptChanges()
End If
Next
Dim GridStyle As DataGridTableStyle = New DataGridTableStyle()
ds1.Tables.Add(DataTable)
With DataGrid1
.DataSource = ds1.Tables(0)
.TableStyles.Add(GridStyle )
End With
Catch otherexcep As Exception
MsgBox(otherexcep.Message, , "Exception")
Exit Sub
End Try
AddHandler ds1.Tables(0).RowChanged, New DataRowChangeEventHandler( AddressOf OnRowChanged)
End Sub
Help would be greatly appreciated as i need this real urgent like
thanks
matt
I have a form in a windows app with a datagrid attached to it which gets its data from the datatable which i build through some XML data. Problem is when i want to go back into the form and change the data in the table it won't let me. I have tried reseting, clearing and others but hink i am missing something fairly basic.
Your help would be appreciated - The code i have is below
Sub datagrider()
Try
Dim DataTable As New Data.DataTable("FileConten
Dim l As Integer
With DataTable.Columns
.Add("Template_id")
.Add("fleid")
.Add("Account Name")
End With
Dim newIt As ListViewItem
Dim nodelist As XmlNodeList = xmlDoc.SelectNodes("/deid/
Dim node As XmlNode
l = -1
For Each node In nodelist
If node.SelectSingleNode("Tem
l += 1
With DataTable.Rows
.Add(New Object() {})
.Item(l).Item(0) = node.SelectSingleNode("Tem
.Item(l).Item(1) = node.Attributes("fleid").I
.Item(l).Item(2) = node.SelectSingleNode("Acc
End With
DataTable.AcceptChanges()
End If
Next
Dim GridStyle As DataGridTableStyle = New DataGridTableStyle()
ds1.Tables.Add(DataTable)
With DataGrid1
.DataSource = ds1.Tables(0)
.TableStyles.Add(GridStyle
End With
Catch otherexcep As Exception
MsgBox(otherexcep.Message,
Exit Sub
End Try
AddHandler ds1.Tables(0).RowChanged, New DataRowChangeEventHandler(
End Sub
Help would be greatly appreciated as i need this real urgent like
thanks
matt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Problem Solved
ds1.Tables.Clear() at the top - this then caused an error in the grid style section (not shown in the code below) but i just removed this if it was there and then readded it
thanks anyway
ds1.Tables.Clear() at the top - this then caused an error in the grid style section (not shown in the code below) but i just removed this if it was there and then readded it
thanks anyway
ASKER
I am updating it through the addhandler - when they change a cell in the datagrid it updates the xml file
Private Shared Sub OnRowChanged(ByVal sender As Object, ByVal args As DataRowChangeEventArgs)
Dim nodelist As XmlNodeList = xmlDoc.SelectNodes("/deid/
Dim node As XmlNode
For Each node In nodelist
If node.Attributes("fleid").V
node.SelectSingleNode("Amo
End If
Next
xmlDoc.Save(xmlFile)
End Sub
so the changes for this actually happen as they type it in. The problem i have is when they leave this and load new data which i need to insert into the grid which is set by the line in hte code
If node.SelectSingleNode("Tem
Thanks
Matt