Tri*_*tan 3 c# wpf datagrid wpftoolkit wpfdatagrid
我有下一个代码,我定义了一个名为dgQuery的WPF工具包数据网格控件; 我用数据集的信息填充了这个,然后我在dgQuery中插入了一个新的复选框列来检查/取消选中某些行,我展示了部分C#代码:
dgQuery.DataContext = dS.Tables[0];
DataGridTemplateColumn cbCol = new DataGridTemplateColumn();
cbCol.Header = "Opc";
FrameworkElementFactory factory = new FrameworkElementFactory(typeof(CheckBox));
Binding bind = new Binding("IsSelected");
bind.Mode = BindingMode.TwoWay;
factory.SetValue(CheckBox.IsCheckedProperty, bind);
DataTemplate cellTemplate = new DataTemplate();
cellTemplate.VisualTree = factory;
cbCol.CellTemplate = cellTemplate;
dgQuery.Columns.Insert(0, cbCol);
Run Code Online (Sandbox Code Playgroud)
在检查/取消选中dgQuery行的新复选框列后,我将单击一个按钮,仅将我检查的行保存到数据库中.问题是,如何开发用于读取dgQuery的所有行的循环以及让我知道哪些行具有选中/取消选中复选框的条件?请帮我举个例子.
谢谢!!
Ton*_*ion 11
这将在您的数据网格中返回一个"行"
public IEnumerable<Microsoft.Windows.Controls.DataGridRow> GetDataGridRows(Microsoft.Windows.Controls.DataGrid grid)
{
var itemsSource = grid.ItemsSource as IEnumerable;
if (null == itemsSource) yield return null;
foreach (var item in itemsSource)
{
var row = grid.ItemContainerGenerator.ContainerFromItem(item) as Microsoft.Windows.Controls.DataGridRow;
if (null != row) yield return row;
}
}
Run Code Online (Sandbox Code Playgroud)
在wpf datagrid中,行是ItemSource.items ...没有Rows属性!
希望这可以帮助...
| 归档时间: |
|
| 查看次数: |
28105 次 |
| 最近记录: |