Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello master, I have a problem in solving on my datagrid view with combobox inside it.
Can anyone solve this problem.

The Problem:
I have a datagrid to view a database with a specific column, in column "Map Table" I created a combobox as the Value are the column name of Table from the column "legacyclient_maptable_name" in datagrid. I want to tell the main thing that inside the datagrid column "legacyclient_maptable_name" are the name of Table in other database.
As in fact I got only the list of last row in my Combobox List. What I want is that the list of combobox is dynamic according the data in column "legacyclient_maptable_name".

Thank for the help.

File: [ABC.cs]
                DTItems = GetAllItems();
                dataGrid1.ItemsSource = DTItems.DefaultView;
                foreach (DataRow row in DTItems.Rows)
                    //foreach (var item in row.ItemArray)
                    //    MessageBox.Show("data: " + item.ToString());
                    //MessageBox.Show("data: " + row["legacyclient_maptable_name"]);
                        string qGetDM = "SELECT * FROM " + row["legacyclient_maptable_name"]; //basel_f11_normal
                    //## Get ColumnName from datamart database table
                        List<string> MapColumn = dboperation.columnNames(qGetDM, "clientLegacyDM");
                        MapColumns = MapColumn;
                        dtcmbTes.ItemsSource = MapColumns;

<DataGrid AutoGenerateColumns="False" HorizontalAlignment="Left" Margin="12,123,0,176" Name="dataGrid1" Width="1000"
                  ItemsSource="{Binding Path=.,Mode=TwoWay}" SelectionUnit="Cell" CanUserAddRows="False" PreparingCellForEdit="dataGrid1_PreparingCellForEdit">
                <DataGridTextColumn Binding="{Binding parent_id}" Header="Parent ID" />
                <DataGridTextColumn Binding="{Binding report_code}" Header="Report Code" />
                <DataGridTextColumn Binding="{Binding fieldname}" Header="Field Name" />
                <DataGridTextColumn Binding="{Binding fieldlength}" Header="Field Length" />
                <DataGridTextColumn Binding="{Binding xbrlxmltagmapping}" Header="Xbrl Tag Map" />
                <DataGridTextColumn Binding="{Binding mapfield_supportsystem}" Header="mapfield_supportsystem" />
                <!-- MAP TABLE-->

                <DataGridComboBoxColumn x:Name="dtcmbTes"
                                 Header="Map Table" Width="200"
                                 SelectedItemBinding="{Binding mapfield_supportsystem}"
                <!-- ItemsSource="{Binding Path=MapColumns}"
                                 SelectedItemBinding="{Binding mapfield_supportsystem}"-->
                <DataGridTextColumn x:Name="column1" Binding="{Binding legacyclient_maptable_name}" Header="legacyclient_maptable_name" Visibility="Hidden"/>



Table_main structure:

|autoid||Parent ID||Map Table ||legacyclient_maptable_name* |
|0 ||1 ||BlnLaporan||basel_f01 |
|1 ||2 ||UserId ||basel_f11_normal |

Table basel_f01 structure

|0 ||1 ||1200 ||22 |
|1 ||2 ||12 ||12 |

Table basel_f11_normal structure

|autoid||UserId ||UserId2 ||UserId3 |
|0 ||1 ||1500 ||62 |
|1 ||2 ||14 ||77 |

*) legacyclient_maptable_name are name of Table in other database.
#) Map Tableare column name of Table in "legacyclient_maptable_name
Updated 25-Jul-13 17:55pm

1 solution

you can change datasoruce a DataComboboxCell in Datagrid;

string[] values=new string[] { "parviz","ali","abass"};

DataGridViewComboBoxCell M =(DataGridViewComboBoxCell ) DgvTable.Rows[n].Cells[m];
M.datasource = values;

use can that code in valuechanged of datagridview
Share this answer
[no name] 25-Jul-13 23:22pm    
Thanks for the mention of my problem. Perhaps I still didn't can get it what you mean.
Actually I have declare my data from database into list method.
List<'string'> MapColumn = dboperation.columnNames(qGetDM, "clientLegacyDM");
The Value are:["parviz","ali","abass"]

equal your code:
string[] values=new string[] { "parviz","ali","abass"};

for this code I couldn't know it clearly well:
"DataGridViewComboBoxCell M =(DataGridViewComboBoxCell ) DgvTable.Rows[n].Cells[m];
M.datasource = values;"
Pleased describe it more detail. Thanks
Relative problem link:
Parviz Bazgosha 5-Aug-13 11:08am    
you set a datasource for every cell .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900