datagrid

On a Button Click, making multiple cells editable in a selected row of a ReadOnly DataGrid

荒凉一梦 提交于 2020-05-17 07:12:27
问题 Question : In a ReadOnly DataGrid, how can we place multiple cells, in a selected row, in Edit mode? In following ReadOnly DataGrid, the btnEdit_Click event (shown below) successfully places the FirstName column cell of selected row in the edit mode. But I need both FirstName and LastName column cells in the edit mode. If I enclose the entire code of that event in a for loop as for (int i=2; i <=3; i++){...} only the last cell ( LastName ) column gets the edit mode. Remark : All other rows

DataGrid CellEditEnding event not firing on a cell editing inside DataGridTemplateColumn

↘锁芯ラ 提交于 2020-05-17 05:46:12
问题 In the MyDatagrid_CellEditEnding(...) event (shown below) I am capturing the edited value of a cell whenever a cell of one of the three columns is edited by a user. After editing cell in second or third column, when I move out of that cell, I can see the CellEditEnding event getting called. But the same is not true for the first column that is a DataGridTemplateColumn column. That is, when I change a date in any cell in the first DataGridTemplateColumn , and move the cursor out of the cell,

Align DataGrid Column Header to Center

浪子不回头ぞ 提交于 2020-05-09 19:26:01
问题 I need to align WPF DataGrid Column Header text to Center . I created a style and attached that using the HeaderStyle property as below. Style <Window.Resources> <Style x:Key="CenterGridHeaderStyle" TargetType="DataGridColumnHeader"> <Setter Property="HorizontalContentAlignment" Value="Center"/> </Style> </Window.Resources> Column <DataGridTextColumn Binding="{Binding Path=Name}" Header="Name" IsReadOnly="True" HeaderStyle="{DynamicResource CenterGridHeaderStyle}"/> But this does not align

How to create in C# WPF a DataGrid dynamic columns binded to an observable collection of dynamic properties types at runtime

自古美人都是妖i 提交于 2020-05-08 05:54:36
问题 I'm trying to create in C# WPF a DataGrid with dynamic columns binded to an observable collection of dynamic properties types created at runtime. This is my code : View WPF <DataGrid ItemsSource="{Binding MyCollectionVM, Mode=OneWay}" AutoGenerateColumns="True"> </DataGrid> Then in my ViewModel : public class MyStatiClass { public int ID { get; set; } public string Name { get; set; } public string Address { get; set; } } // Main View Model, using MVVMLight library public class MainViewModel :

How to create in C# WPF a DataGrid dynamic columns binded to an observable collection of dynamic properties types at runtime

不羁岁月 提交于 2020-05-08 05:53:18
问题 I'm trying to create in C# WPF a DataGrid with dynamic columns binded to an observable collection of dynamic properties types created at runtime. This is my code : View WPF <DataGrid ItemsSource="{Binding MyCollectionVM, Mode=OneWay}" AutoGenerateColumns="True"> </DataGrid> Then in my ViewModel : public class MyStatiClass { public int ID { get; set; } public string Name { get; set; } public string Address { get; set; } } // Main View Model, using MVVMLight library public class MainViewModel :

How to perform Single click checkbox selection in WPF DataGrid with IEditableObject object

浪尽此生 提交于 2020-04-13 17:54:05
问题 The default behavior of DataGridCheckBoxColumn is that the user has to click twice to change the checkbox value. In the How to perform Single click checkbox selection in WPF DataGrid topic there are a couple of solutions which work, but there is a problem - is you have a viewmodel object in code behind, which implements the IEditableObject interface, then the EndEdit method doesn't execute. Any idea how to make single click work and also preserve the IEditableObject functionallity? 回答1: You

WPF filter datagrid through textbox

独自空忆成欢 提交于 2020-04-12 07:25:27
问题 I have been searching everywhere and I just cannot make it.. I have a simple DataGrid : <DataGrid Name="myGrid" HorizontalAlignment="Left" Height="399" Margin="272,150,0,0" VerticalAlignment="Top" Width="735"/> When my form loads. I have this function to fill datagrid : public MainWindow() { InitializeComponent(); myGrid.ItemsSource = datatble; } I have a TextBox name "txtSearch" and my goal is to filter the datagrid and find all rows that contain txtSearch.Text (and hide the other rows)

Automatic tooltip when text is trimmed in DataGrid

我的未来我决定 提交于 2020-04-10 06:25:22
问题 My application runs with C# and WPF (.net framework 4.0). My goal is to have a DataGrid in which the text in the cells is trimmed with an ellipsis, and automatically has a tooltip with the full text displayed only if the text in the cell is actually trimmed. Solution 1 : I'm currently using this to know if the text is trimmed or not: http://tranxcoder.wordpress.com/2008/10/12/customizing-lookful-wpf-controls-take-2/ The problem is that it only works when I resize the columns. The tooltips don

datagrid中column中的formatter属性

别等时光非礼了梦想. 提交于 2020-04-08 01:41:14
在这里红色的部分field字段显示得信息是,返回数据中的department得值,再此示例中因为返回数据是department是一个obj所以要用formatter属性进行重新的字段名定义 var column_views = [ {field: 'user_id', title: '工号', width: 70, sortable: true, align: 'center'}, {# {field: 'knowtype', title: '类型', width: 100, sortable: true},#} {field: 'name', title: '用户名称', width: 150, sortable: true, align: 'center'}, {field: 'department', title: '所属部门', width: 200, sortable: true, align: 'center', formatter:function(value, row, index){ return row.department.name }}, {field: 'email', title: '用户名称', width: 70, sortable: true, align: 'center'}, //{ title: '操作', width: 100,

用Repeater控件显示数据

时光怂恿深爱的人放手 提交于 2020-04-06 04:07:12
如果你正在使用ASP.NET,你一定对DataGrid 控件 非常熟悉。DataGrid 控件 提供了各种特性,通过这些特性可以很容易地在一个Web页面上以列表形式显示数据。但是,如果你不想使用HTML表格形式呢?此时,可以使用一个DataGrid的一个鲜为人知的兄弟 控件 ,即Repeater 控件 。Repeater 控件 提供显示你所需要数据的灵活性。 Repeater 控件 是什么? Repeater是一个可重复操作的 控件 ,也就是说,它通过使用模板显示一个数据源的内容,而你可以很容易地配置这些模板。Repeater包含如标题和页脚这样的数据,它可以遍历所有的数据选项并应用到模板中。 与DataGrid和DataList 控件 不同,Repeater 控件 并不是由WebControl类派生而来。所以,它不包括一些通用的格式属性,比如控制字体,颜色,等等。然而,使用Repeater 控件 ,HTML(或者一个样式表)或者ASP.NET类可以处理这些属性。 HTML在哪里? Repeater 控件 与DataGrid (以及DataList) 控件 的主要区别是在于如何处理HTML。ASP.NET建立HTML代码以显示DataGrid 控件 ,但Repeater允许开发人员决定如何显示数据。所以,你可以选择将数据显示在一个HTML表格中或者一个顺序列表中