Tag: datagrid

为什么ItemContainerGenerator.ContainerFromIndex()返回null以及如何避免此行为?

我正在使用此代码段来分析我在数据网格上选择的行。 for (int i = 0; i < dgDetalle.Items.Count; i++) { DataGridRow row = (DataGridRow)dgDetalle.ItemContainerGenerator.ContainerFromIndex(i); FrameworkElement cellContent = dgDetalle.Columns[0].GetCellContent(row); // … code … } 循环运行平稳,但在处理某些索引时,第二行会抛出一个空exception。 MSDN的文档说如果“如果项目没有实现”, ItemContainerGenerator.ContainerFromIndex(i)将返回null,但这无助于我猜测如何获得所需的值。 如何扫描所有行? 还有别的办法吗? UPDATE 我正在使用这个片段来读取CheckBox ,如此处所述。 所以除非我改变了很多东西,否则我根本不能使用绑定或ItemSource 。 我不能。 我正在进行代码维护。

WPF DataGrid使用sums和其他字段进行分组

我有一个DataGrid绑定到集合,我想分组。 这是代码 采集: private string _ID; private string _Descript; private decimal _Amount; public string ID { get { return _ID; } set { _ID = value; NotifyPropertyChanged(“ID”); } } public decimal Amount { get { return _Amount; } set { _Amount = value; NotifyPropertyChanged(“Amount”); } } public string Descript { get { return _Descript; } […]

DataGrid中的CSV /文本Wpf

我似乎无法弄清楚如何在DataGrid中添加我的CSV文件。 有人可以解释一下我的方法应该是什么吗? 假设我的csv文件中包含以下内容的CSV文件: ID;Name;Age;Gender 01;Jason;23;Male 02;Lela;29;Female 真的需要一些帮助

WPF工具包DataGrid SelectionChanged获取单元格值

请帮助我,我试图从SelectionChangedEvent中的选定行获取Cell [0]的值。 我只是设法得到许多不同的Microsoft.Windows.Controls,我希望我错过了一些愚蠢的东西。 希望我能从这里得到一些帮助…… private void datagrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { Microsoft.Windows.Controls.DataGrid _DataGrid = sender as Microsoft.Windows.Controls.DataGrid; } 我希望它会像… _DataGrid.SelectedCells[0].Value; 但是.Value不是一个选择…. 非常感谢这一直让我发疯! 担

在WPF中过滤DataGrid

我用这个加载数据网格中的对象列表: dataGrid1.Items.Add(model); 该model成为数据库中的数据。 它有Id(int) , Name(string)和Text(string) 在我的数据网格中,我只显示model的名称。 当我在文本框中输入内容时,如何现在过滤数据网格? 我在这个页面: http : //msdn.microsoft.com/en-us/library/vstudio/ff407126(v=vs.100).aspx但我不明白那里的代码我无法解释如何我应该为我的问题转移那个。

如何在使用自定义DataSource时隐藏DataGridView的列?

我在c#中有一个小应用程序,它有一个使用以下内容填充的DataGridView: grid.DataSource = MyDatasource array; MyClass保存列的结构,它看起来像这样: class MyDatasource { private string column1; private string column2; public MyDatasource(string arg1, string arg2) { this.column1 = arg1; this.column2 = arg2; } public string column1 { get { return this.column1; } set { this.column1 = value; } } public string column2 { get { return this.column2; } set { […]

Wpf DataGrid添加新行

我设法让DataGrid显示添加新项目的新行。 我现在面临的问题是我希望wpf DataGrid的其余部分中的数据只读,并且只能编辑新行。 目前这是我的DataGrid外观。 但由于我保持列只读,所以新行也添加为只读,这是我不想要的。

在ViewModel中使用CollectionViewSource的正确方法

我使用Drag和Drop将Data Source对象(DB模型)绑定到DataGrid (基本上遵循WPFentity framework数据绑定中的这个示例)。 这个实现一切正常。 XAML .. 代码背后 private void Window_Loaded(object sender, RoutedEventArgs e) { System.Windows.Data.CollectionViewSource categoryViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource(“categoryViewSource”))); _context.Categories.Load(); categoryViewSource.Source = _context.Categories.Local; } 视图模型 public MainWindow() { InitializeComponent(); this.DataContext = new MyViewModel(); } 但是,当我尝试在ViewModel中使用相同的代码时,它不起作用( FindResource不可用),此外,我不认为这是正确的方法(即在MVVM中使用x:Key )。 我非常感谢任何帮助,指出使用DataGrid实现CollectionViewSource和DataBinding的正确方法。

DataGrid显示图像的路径而不是图像本身

以下行最终显示路径而不是它导致的图像。 AutoGenerateColums设置为true,将其设置为false将以完全空行结束。 System.Data.DataTable DataTable = new System.Data.DataTable(); System.Data.DataColumn DataColumn = new System.Data.DataColumn(); Uri uri = new Uri(@”C:/Users/User/Desktop/szagdoga/error.png”); BitmapImage img = new BitmapImage(uri); DataColumn.DataType = img.GetType(); DataColumn.ColumnName = (“this”); DataTable.Columns.Add(“Test #”); DataTable.Columns.Add(DataColumn); DataTable.Columns.Add(“Min Range”); DataTable.Columns.Add(“Max Range”); DataTable.Columns.Add(“Result”); for (int i = 6; i <50; i++) DataTable.Rows.Add(ExcelFile[0, i],img, ExcelFile[1,i],0,0,0); ChannelDataGrid.ItemsSource = DataTable.DefaultView; 请帮我以某种方式显示图像! 谢谢。

将Datagrid导出为ex​​cel asp

什么是将Datagrid导出为ex​​cel的最佳方法? 我没有任何经验将datagrid导出到excel,所以我想知道你们如何将datagrid导出到excel。 我读到有很多方法,但我想只是简单地导出excel到datagrid function.i我正在使用asp.net C# 干杯..