0

Intent:
I'm trying to create a simple GUI application (VB Desktop) that will allow me to modify an XML file's nodes which contains the program settings and table definitions for an application.

The GUI application's datagridview contains three columns: colA, colB, colC. ColA should be the direct value from an XML Node. ColB and ColC are values retrieved from XML but should be expressed as a selected value from a drop down list embedded into the column for each row of the datagridview.

Problem:
I loop through the retrieved values from XML to create a datatable containing the values. I then assign that datatable as the datasource for the datagridview. HOW do I assign the values in the DATATABLE to a pre-defined column as a DataGridViewComboBoxColumn already in the DataGridView created in the Visual Studio gui via "edit columns." When I use the datatable the columns are bound in but I don't know how to attack the combo-box(DDL) issue.

Code Info:

XMLContainer:
0.Column Name
1.Column DataType
2.Routine

'The code below assigns the retrieved XML node values into a datatable
'which is assigned as the datasource for a datagridview
Dim table As DataTable = New DataTable()
Dim column As DataColumn
Dim row As DataRow

'This container has all the nodes needed for evaluation
'The child nodes are column names which contain 3 elements
'Column Name, DBType, Routine

Dim my_Container = xDoc.Descendants("TABLES").Descendants("Table_Name").Elements
        For i = 0 To my_Container.Count - 1
         
'Column Name
row = table.NewRow
row("Column Name") = my_Container.ElementAt(i).Descendants.ElementAt(0).Value

'DBType         
row = table.NewRow
row("SQLDB Type") = my_Container.ElementAt(i).Descendants.ElementAt(1).Value

'Routine Code
row = table.NewRow
row("Column Name") = my_Container.ElementAt(i).Descendants.ElementAt(2).Value

'Add the completed row to the table
table.Rows.Add(row)

Next

'assign the created table as the datagridview's data source
Me.gvData.DataSource = table

Desired DataGridview:
----------------------------------------------------------------------------
Column Name||||||||||||||| SQLDbType||||||||||||||||||||||||||||||||Routine|||||||||
----------------------------------------------------------------------------
Column 1 |||||||||COMBOBOX: SqlDbType.VarChar||||||||COMBOBOX: VALUE (V)||||
----------------------------------------------------------------------------
Column 2||||||||||COMBOBOX: SqlDbType.Image||||||||||COMBOBOX: DATE_TIME (V)
----------------------------------------------------------------------------
Column 3||||||||||COMBOBOX: SqlDbType.SmallInt|||||||COMBOBOX: IGNORE (V)|||
----------------------------------------------------------------------------

XML Layout:

<ROOT>
    <SYSTEM_SETTINGS>
        <CONNECTION>
           Scrambled Connection String
        </CONNECTION>
    </SYSTEM_SETTINGS>
   
 <USERS>
        <USER UID="0">
            <ACTIVE_USER>N</ACTIVE_USER>
            <DEVICE_NAME>Device Name</SCANNER_NAME>
        </USER>
        <USER UID="1">
            <ACTIVE_USER>Y</ACTIVE_USER>
            <SCANNER_NAME>Device Name</SCANNER_NAME>
        </USER>
       
 </USERS>
       
     <TABLES>
        <MYTABLE COL_COUNT="18">
        <COLUMN_NAME_AS_PARENT_NODE0>
           <COLUMN_NAME>ID</COLUMN_NAME>
           <DATA_TYPE>SqlDbType.VarChar</DATA_TYPE>
           <ROUTINE_CODE>VALUE</ROUTINE_CODE>
        </COLUMN_NAME_AS_PARENT_NODE0>

      <COLUMN_NAME_AS_PARENT_NODE1>
        <COLUMN_NAME>IIMG_VND_X6</COLUMN_NAME>          
        <DATA_TYPE>SqlDbType.VarChar</DATA_TYPE>
        <ROUTINE_CODE>VALUE</ROUTINE_CODE>
      </COLUMN_NAME_AS_PARENT_NODE1>
       </MYTABLE>

   </TABLES>
    <STORED_PROCEDURES>
        <SP_MYTABLE>
            <PROCEDURE0>
                <PROCEDURE_NAME>SP_NAME</PROCEDURE_NAME>
                <USE_DEVICE>Y</USE_DEVICE>
                <SKIP_ON>N</SKIP_ON>
                <COLUMN_SKIP_STRING>000000000000000000000</COLUMN_SKIP_STRING>
            </PROCEDURE0>
            <PROCEDURE01>
                <PROCEDURE_NAME>SP_NAME2</PROCEDURE_NAME>
                <USE_DEVICE>Y</USE_DEVICE>
                <SKIP_ON>Y</SKIP_ON>
                <COLUMN_SKIP_STRING>000000000000000000000</COLUMN_SKIP_STRING>
            </PROCEDURE01>
            <PROCEDURE02>
                <PROCEDURE_NAME>SP_Name3</PROCEDURE_NAME>
                <USE_DEVICE>N</USE_DEVICE>
                <SKIP_ON>N</SKIP_ON>
                <COLUMN_SKIP_STRING>111111111111111111</COLUMN_SKIP_STRING>
            </PROCEDURE02>
       </SP_MYTABLE>
     </STORED_PROCEDURES>
 </ROOT>

Edited by Learning_Curve: n/a

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Learning_Curve
0

I decided against using a datatable to make a bound dataset. I just wound up populating the gridview directly.

If TableName IsNot Nothing Then
            PrepGVData()
            'Temp Table to hold data
            Dim table As DataTable = New DataTable()
            'Row to add
            Dim row As DataRow
            'Get the table data about the selected node using the table name
            Dim my_Container = xDoc.Descendants("TABLES").Descendants(TableName).Elements
            For i = 0 To my_Container.Count - 1
                row = table.NewRow
                gvData.Rows.Add(row)
                'This is the column name
                gvData.Rows(i).Cells(0).Value = my_Container.ElementAt(i).Descendants.ElementAt(0).Value
                'This is the SQL parameter type
                gvData.Rows(i).Cells(1).Value = my_Container.ElementAt(i).Descendants.ElementAt(1).Value
                'This is the Routine code item used to determine if the value or date-time should be used
                gvData.Rows(i).Cells(2).Value = my_Container.ElementAt(i).Descendants.ElementAt(2).Value
            Next
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.