Reset Datagrid and Datatable

Posted on 2004-08-21
Last Modified: 2012-05-05

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()
        Dim DataTable As New Data.DataTable("FileContents")
        Dim l As Integer

        With DataTable.Columns
            .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("Template_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("Template_id").InnerText
                    .Item(l).Item(1) = node.Attributes("fleid").InnerText
                    .Item(l).Item(2) = node.SelectSingleNode("Account_Name").InnerText
                End With
            End If

        Dim GridStyle As DataGridTableStyle = New DataGridTableStyle()

        With DataGrid1
            .DataSource = ds1.Tables(0)
        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


Question by:cafferm
  • 2
LVL 18

Accepted Solution

DotNetLover_Baan earned 500 total points
ID: 11864674
Hi there,
where are you updating data ? I don't see the code for that. Here you are just populating the table with the XML data. How are you updating it ?

Author Comment

ID: 11866750

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/deFile")
        Dim node As XmlNode

        For Each node In nodelist
            If node.Attributes("fleid").Value = args.Row("fleid").ToString() Then
                node.SelectSingleNode("Amount").InnerText = args.Row("Account_Name").ToString()
            End If
    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("Template_id").InnerText = lblid.Text Then ' where lblid is selected detail on another form



Author Comment

ID: 11867964
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question