Solved

Reset Datagrid and Datatable

Posted on 2004-08-21
3
726 Views
Last Modified: 2012-05-05
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("FileContents")
        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("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
                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
0
Comment
Question by:cafferm
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 500 total points
Comment Utility
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 ?
0
 

Author Comment

by:cafferm
Comment Utility
Hi

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
        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("Template_id").InnerText = lblid.Text Then ' where lblid is selected detail on another form

Thanks

Matt
0
 

Author Comment

by:cafferm
Comment Utility
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
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now