本文介绍了带有组合框的数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好,我在使用内置的combobox解决我的数据网格视图时遇到问题。 任何人都可以解决这个问题。 问题: 我有一个datagrid来查看具有特定列的数据库,在Map Table列中我创建了一个组合框,因为Value是legacyclient_maptable_name列中Table的列名在datagrid中。我想告诉主要的事情,datagrid列中的legacyclient_maptable_name是其他数据库中Table的名称。 实际上我只得到了我的Combobox列表中最后一行的列表。我想要的是,根据legacyclient_maptable_name列中的数据,组合框列表是动态的。 感谢您的帮助。 问候, 文件:[ABC.cs]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.Regards,File: [ABC.cs]//###NEW dboperation.open_connection("True"); DTItems = GetAllItems(); dataGrid1.ItemsSource = DTItems.DefaultView; //###NEW foreach (DataRow row in DTItems.Rows) { //foreach (var item in row.ItemArray) //{ // MessageBox.Show("data: " + item.ToString()); //MessageBox.Show("data: " + row["legacyclient_maptable_name"]); //##DatagridComboBoxColumn### string qGetDM = "SELECT * FROM " + row["legacyclient_maptable_name"]; //basel_f11_normal //## Get ColumnName from datamart database table //MessageBox.Show(qGetDM); List<string> MapColumn = dboperation.columnNames(qGetDM, "clientLegacyDM"); MapColumns = MapColumn; dtcmbTes.ItemsSource = MapColumns; //##DatagridComboBoxColumn### //} } 文件:[ABC.xaml]file:[ABC.xaml]<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"> <DataGrid.Columns> <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}"--> </DataGridComboBoxColumn> <DataGridTextColumn x:Name="column1" Binding="{Binding legacyclient_maptable_name}" Header="legacyclient_maptable_name" Visibility="Hidden"/> </DataGrid.Columns> </DataGrid> 数据库模型 表_主要结构: | autoid ||父ID || Map Table || legacyclient_maptable_name * | | 0 || 1 || BlnLaporan || basel_f01 | | 1 || 2 || UserId || basel_f11_normal | 表basel_f01结构 | autoid || BlnLaporan || BlnLaporan2 || BlnLaporan3 | | 0 || 1 || 1200 || 22 | | 1 || 2 || 12 || 12 | 表basel_f11_normal结构 | autoid || UserId || UserId2 || UserId3 | | 0 || 1 || 1500 || 62 | | 1 || 2 || 14 || 77 | *)legacyclient_maptable_name是其他数据库中Table的名称。 #)在legacyclient_maptable_nameDATABASE MODELTable_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|autoid||BlnLaporan||BlnLaporan2||BlnLaporan3||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推荐答案你可以在Datagrid中更改datasoruce一个DataComboboxCell; string [] values = new string [] {parviz ,ali,abass}; DataGridViewComboBoxCell M =(DataGridViewComboBoxCell)DgvTable.Rows [n] .Cells [m]; M.datasource = values; 使用可以使用datagridview的valuechanged代码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 这篇关于带有组合框的数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-30 07:41