访问单元格对行的控制 [英] Accessing the cell’s control of the row

查看:77
本文介绍了访问单元格对行的控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WPF数据网格,我已以编程方式添加了列DataGridComboBoxColumn和DataGridTemplateColumn.

我希望该列的每一行(每个comboBox)具有不同的数据源,可能第一行的下拉列表将包含5个项目,第二行的下拉列表将包含3个项目.


I am using the WPF datagrid, I have added the columns DataGridComboBoxColumn, DataGridTemplateColumn programatically.

I want every row (every comboBox) of the the column with the different datasource may be first row’s dropdown will have 5 items and second row’s dropdown will have 3 items.


DataGridComboBoxColumn colcombo = new DataGridComboBoxColumn();
colcombo.Header = "FirstName";
dataGrid1.Columns.Add(colcombo);
         //===================================================================
DataGridTemplateColumn cbColcmbBox = new DataGridTemplateColumn();           
cbColcmbBox.Header = "LastNamecombo";
FrameworkElementFactory factorycombo = new 	FrameworkElementFactory(typeof(ComboBox));
DataTemplate cellTemplatecomb = new DataTemplate();
cellTemplatecomb.VisualTree = factorycombo;
cbColcmbBox.CellTemplate = cellTemplatecomb;            
dataGrid1.Columns.Add(cbColcmbBox);



如果要以编程方式访问DataGridTemplateColumn ,这是添加DataGridTemplateColumn 的正确方法吗?



Is this the correct way to add the DataGridTemplateColumn , if I want to access this programatically ?

推荐答案

如果要添加具有多个数据源的datagrid的每一行下拉菜单,然后上面的逻辑想要工作,那么您必须在rowload事件上编写代码.

拿一个带有空白堆栈面板的模板列,在rowaoad事件中,使用具有不同databasource的新下拉列表,并将其添加到相对的堆栈面板中.

If you want to add every row of your datagrid with multiple datasource dropdown then above logic want work, then you have to write code on rowload event.

Take a tempate column with blank stackpannel and in rowaoad event take new dropdown with different databasource and add it in relavnt stackpannel.

stkpnl.child.add(objdropdown);



谢谢,
阿米特·帕特尔(Amit Patel)



Thanks,
Amit Patel


您好,谢谢您,我尝试了以下操作,但是无法正常工作..plz检查代码------------添加了资源---- ----------- --------添加了列----------------------------- --------------- DataGridTemplateColumn dgTemplateColumn = new DataGridTemplateColumn(); dgTemplateColumn.Width = new DataGridLength(1,DataGridLengthUnitType.Star); dgTemplateColumn.Header =管理选项"; dgTemplateColumn.CellTemplate = this.FindResource("manageAreaCellTemplate")作为DataTemplate; dataGrid1.Columns.Add(dgTemplateColumn); ------------------- void dataGrid1_LoadingRow(对象发送方,Microsoft.Windows.Controls.DataGridRowEventArgs e){DataTemplate dt =(DataTemplate)e.Row.FindResource("manageAreaCellTemplate" );对象stk = dt.LoadContent(); StackPanel stk1 =新的StackPanel(); stk1 =(StackPanel)stk; ComboBox cmb =新的ComboBox(); PortInfoCollection portInfoCollection =新的PortInfoCollection(); cmb.ItemsSource = portInfoCollection; cmb.SelectedValuePath =访问"; cmb.DisplayMemberPath =端口"; stk1.Children.Add(cmb); }组合框未填充..在网格中
Hi thanks for ur ans, I have tried following but not working ..plz check the code ------------added resource --------------- --------added column-------------------------------------------- DataGridTemplateColumn dgTemplateColumn = new DataGridTemplateColumn(); dgTemplateColumn.Width = new DataGridLength(1, DataGridLengthUnitType.Star); dgTemplateColumn.Header = "Manage Options"; dgTemplateColumn.CellTemplate = this.FindResource("manageAreaCellTemplate") as DataTemplate; dataGrid1.Columns.Add(dgTemplateColumn); ------------------- void dataGrid1_LoadingRow(object sender, Microsoft.Windows.Controls.DataGridRowEventArgs e) { DataTemplate dt = (DataTemplate)e.Row.FindResource("manageAreaCellTemplate"); object stk = dt.LoadContent(); StackPanel stk1 = new StackPanel(); stk1 =(StackPanel)stk; ComboBox cmb = new ComboBox(); PortInfoCollection portInfoCollection = new PortInfoCollection(); cmb.ItemsSource = portInfoCollection; cmb.SelectedValuePath = "Visits"; cmb.DisplayMemberPath = "Port"; stk1.Children.Add(cmb); } combo box is not getting populated..in the grid


这篇关于访问单元格对行的控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆