将所有数据从 wpf DataGrid 导出到 List
我来自俄罗斯!我为我的英语感到抱歉!如何将 wpf DataGrid 中的所有内容放入集合列表中? DataGrid 中的这些数据来自 int [,] m_intArray = new int [5, 5] 数组以及另外附加的列 DataGridComboBoxColumn
private int[,] m_intArray = new int[5, 5];
private DataGridComboBoxColumn box = new DataGridComboBoxColumn();
private List<Vary> col1 = new List<Vary>();
public class Vary
{
public int vy { get; set; }
}
private void Create()
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
m_intArray[i, j] = (i * 10 + j);
}
}
col1.Add(new Vary { vy = 1 });
col1.Add(new Vary { vy = 2 });
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Create();
c_dataGrid.ItemsSource = BindingHelper.GetBindable2DArray<int>(m_intArray);
box.Header = "Y";
box.ItemsSource = col1;
box.DisplayMemberPath = "vy";
box.SelectedItemBinding = new Binding("vy");
c_dataGrid.Columns.Add(box);
c_dataGrid.Items.Refresh();
}
选择 ComboBox 中的值并按“生成”按钮将所有值放入集合 List 中进一步研究这些值...... 我该怎么办?
i'm from Russia! I'm sorry for my english! How do I put the all contents from wpf DataGrid in collection List ?
These data in a DataGrid from an array of int [,] m_intArray = new int [5, 5] and additionally attached column DataGridComboBoxColumn
private int[,] m_intArray = new int[5, 5];
private DataGridComboBoxColumn box = new DataGridComboBoxColumn();
private List<Vary> col1 = new List<Vary>();
public class Vary
{
public int vy { get; set; }
}
private void Create()
{
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
m_intArray[i, j] = (i * 10 + j);
}
}
col1.Add(new Vary { vy = 1 });
col1.Add(new Vary { vy = 2 });
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Create();
c_dataGrid.ItemsSource = BindingHelper.GetBindable2DArray<int>(m_intArray);
box.Header = "Y";
box.ItemsSource = col1;
box.DisplayMemberPath = "vy";
box.SelectedItemBinding = new Binding("vy");
c_dataGrid.Columns.Add(box);
c_dataGrid.Items.Refresh();
}
After selecting the values in the ComboBox and press the button "Generate" to put all the values in the collection List for further work with these values ...
How do I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该考虑在存储整数集合的视图代码中创建一个属性或字段。如果您有它,您可以将其绑定到数据网格的数据源,然后重用它(例如将其转换为通用整数列表)。
还请考虑使用一些设计模式(如 MVVM),因为仅使用代码隐藏肯定会遇到很多问题。
You should consider creating a property or a field in your view's code behind storing your collection of integers. If you have it, you can bind it to your datagrid's data source and then reuse it (for example to convert it to a generic list of integers).
Please also consider using some design pattern (like MVVM), because you definitely will have lots of problems using just code behind.