Update DatagridView control after Dataset loaded

elainec351

Member
Joined
Feb 28, 2008
Messages
12
Programming Experience
Beginner
I am attempting to update one column of data of my datagridview based on the data entered into another column from my dataset. I am completely new to vb .net so any help at all will be welcome.

I have a datagridview that has 4 columns of data - 3 of which get their data from a dataset. I would like to create an if statement that checks one column of data to determine what to populate the empty one with - something like:

If clmIssueCountry = "FRA" then clmProduct = "Local" Else clmProduct = "International"

I realize that the code is completely wrong for updating datagrid controls, but I cannot find the proper syntax or determine that this is even possible.

Thanks for any help you are able to provide.
 
Last edited:
Still confused

Thank you so much for taking the time to help me out. :) Unfortunately, I am still just as confused as before. :confused:

The data that is coming in from the XML Files does not appear to be going into a DataTable, just the DataSet (I realize that I may be completely wrong on this but....). Evertime I try to add a DataTable within the dataset, the code below no longer runs. It stops at the dgvTaxRefunds.DataMember = "refund" line. It works just fine as long as I don't add any extra DataTables to the DataSet.

My code is below, so if I am not getting this right can you help me out again?

VB.NET:
 Public Sub ReadXml()
        Dim settings As New XmlReaderSettings()
        Dim sXMLFile As String

        Dim sXMLFileLocation As String = "P:\"
        Dim currDir As String = Directory.GetCurrentDirectory

        Try
            Directory.SetCurrentDirectory(sXMLFileLocation)
        Catch nopath As Exception
            MsgBox("REX XML Files directory not available.  Please make sure USB object is connected.")
            Exit Sub
        End Try

        For Each sXMLFile In Directory.GetFiles(sXMLFileLocation, "*.xml")
            Dim lfx As XmlDocument = New XmlDocument
            Try
                lfx.Load(sXMLFile)
                Dim reader As XmlReader = XmlReader.Create(sXMLFile, settings)
                settings.ConformanceLevel = ConformanceLevel.Fragment
                settings.IgnoreWhitespace = True
                settings.IgnoreComments = True
                Dim nodetransact As New XmlNodeReader(lfx)
                If nodetransact.MoveToContent() = XmlNodeType.Element And nodetransact.Name = "transaction" _
                    And nodetransact.GetAttribute("transactionType").Equals("refund") Then
                    dsXMLData.ReadXml(sXMLFile)
                    dgvTaxRefunds.DataSource = dsXMLData
                    dgvTaxRefunds.DataMember = "refund"
                End If

            Catch empty As XmlException
            Finally
                ' Finished with XmlDocument
                lfx = Nothing
                Directory.SetCurrentDirectory(currDir)
            End Try
        Next
    End Sub
 
Sorry I forgot to add the datagridview details.

There is only one datagridview object with the following columns:
Product (Text Box)
Amount (Text Box)
Issuing Country (Text Box)
Cheque No (Text Box)
Fee (Text Box)
Confirm (check box)
 
VB.NET:
Dim exp As String = "IIF(clmIssueCountry = 'FRA', 'Local', 'International')"
dsXMLData.Tables("refund").Columns("clmProduct").Expression = exp
If the clmProduct doesn't exist already you can add it
VB.NET:
dsXMLData.Tables("refund").Columns.Add("clmProduct", GetType(String), exp)
 
Thank you so much for taking the time to help me out. :) Unfortunately, I am still just as confused as before. :confused:

The data that is coming in from the XML Files does not appear to be going into a DataTable, just the DataSet (I realize that I may be completely wrong on this but....).

Erm. A DataSet is merely a collection of DataTables, it holds not data itself.
To understand better the forces at work I recommend that you look at what is in the DataSet

Your code contains a lot of unnecessary crap, i'm afraid. The line of code that is dsXMLData.ReadXml(sXMLFile) is perfectly capable of reading an XML file, you dont need to do all this messing about with XMLReader.
Put a breakpoint after the dsXMLData.ReadXml(sXMLFile) line and when the code breaks, select (highlight/click drag so it goes blue) the word dsXMLData then point to it. A tooltip appears with a magnifying glass in. Click the Magnifying Glass

A dataset viewer opens up. This is your dataset. In the combo you can choose which table to look at. You can see the data in that table, in the grid.

Suppose you choose the table called refundfrom the combo. You see the data. Are you sure your dataset HAS a table called refund? Remember its case sensititve!

Hence, if you were to say:

myDataGridView.DataSource = dsXMLData.Tables("refund")

your datagrid on your form would show the same data.


There is no problem adding tables to this dataset.. But why do you wanna do that?
 
Very Helpful

Thank you for giving me the extra information. I will do as asked and explore Datasets further. I am pretty new to this VB .net programming stuff so will probably be confused for quite awhile.

I initially wanted to add a table to have something to compare the Issuing Country data to and the add the relevant data into the Product column. A prior post showed my how to add the If statement without the need of the extra table.

Thanks

Elaine
 

Latest posts

Back
Top