wpfdatagrid

How to retain DataGrid group headers from scrolling in WPF?

家住魔仙堡 提交于 2019-12-08 08:39:12
问题 When a DataGrid is filled with many entries so that the vertical scrollbar appears, I don't want the DataGrid scroll viewer to hide the group headers. Instead, I want to have a ScrollBar per each group . In my case, there will always be just two (2) groups, so there will be 0-2 scrollbars. Here's a minimalistic sample code: http://www.wpftutorial.net/datagrid.html#grouping Customers = new ListCollectionView(_customers); Customers.GroupDescriptions.Add(new PropertyGroupDescription("Gender"));

DataGrid RowStyle - Binding Value in DataTrigger

↘锁芯ラ 提交于 2019-12-08 07:09:10
问题 I want to build a RowStyle which changes the Visibility of the Rows, depending on two conditions (OR). Per default all Rows should be collapsed an be visible whether a Boolean (in ViewModel) is set to True OR a value in the DataTable , bound to the Datagrid , equals to the current User. So, the current user is, of course, a Property too. <DataGrid.RowStyle> <Style TargetType="{x:Type DataGridRow}"> <Setter Property="Visibility" Value="Collapsed" /> <Style.Triggers> <DataTrigger Binding="

WPF DataGrid, cross out the row

谁说我不能喝 提交于 2019-12-08 01:20:50
问题 is it possible to cross out some rows in DataGrid? 回答1: I think you'll have to re-template DataGridRow for this. Played around with it a bit and got the result seen below. Hopefully this is what you had in mind The "cross" Visibility is Binding to a Property called IsCrossed <DataGrid ...> <DataGrid.RowStyle> <Style TargetType="{x:Type DataGridRow}"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> <Setter Property="SnapsToDevicePixels" Value=

C# Load CSV into DataGrid

只谈情不闲聊 提交于 2019-12-07 19:10:33
问题 So I have a CSV file: Header1,Header2,Header3,Header4 Data11,Data12,Data13,Data14 Data21,Data22,Data23,Data24 Data31,Data32,Data33,Data34 Data41,Data42,Data43,Data44 and a DataGrid in an WPF project. I cannot, for the life of me, get it to import. What I was trying to do before was add all the columns ( Header1 , Header2 , Header3 , Header4 ) then add the rows... but there didn't seem to be any way to add rows. So I tried using ItemSource ... but no luck. So... how do I import a CSV file into

WPF - fill data on data grid

孤街浪徒 提交于 2019-12-07 18:48:39
问题 I have the following code and I didnt find any way how to add the data from users to table .I want to do that dynamically . I have create WPF application and add Data Grid and button and I that when I click on the button see the data on the data grid ,how should I proceed? private void Button_Click(object sender, RoutedEventArgs e) { //get user data... DataTable dt = new DataTable("Users Info"); DataGrid.ItemsSource = dt.DefaultView; foreach (var user in users) { string firstName = user

How to get DataGrid row data after user has finished editing row?

妖精的绣舞 提交于 2019-12-07 18:10:40
问题 I want to validate what the user has entered immediately after the user has finished entering a row in a datagrid. What event should I be looking at, and how do I retrieve the row data? Or even better, the object it's bound to? 回答1: Use the RowEditEnding event. private void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e) { YourObject obj = e.Row.Item as YourObject; if (obj != null) { //see obj properties } } 回答2: Event RowEditEnding Data should be in e.Row.DataContext

Style first row in a WPF Datagrid

眉间皱痕 提交于 2019-12-07 17:14:01
问题 I would like to change the styling of the first row (only) in a WPF Datagrid but haven't found how to do it. I wondered about creating a trigger, something like this: <Style TargetType="{x:Type dg:DataGridRow}"> <Style.Triggers> <Trigger Property="SelectedIndex" Value="0"> <Setter Property="Background" Value="Red"/> </Trigger> </Style.Triggers> </Style> But of course this doesn't work since there is no 'SelectedIndex' property on DataGridRow. I have also had some attempts at doing this in my

2-Way databinding with Entity Framework and WPF DataGrid

时光总嘲笑我的痴心妄想 提交于 2019-12-07 16:26:33
I'm having trouble adding an Entity Framework entity to a ObjectContext's EntitySet automatically using the WPF 4.0 DataGrid's add functionality. Here's the setup: DataGrid-->BoundTo-->ListCollectionView-->BoundTo-->EntitySet When I interactively add a row to the DataGrid, the EntitySet does not have a new entity added to it. Updating the row's cell data does in fact update the bound entity's properties, however. Any idea what I could be doing wrong? Here is the XAML for the ListCollectionView: <CollectionViewSource x:Key="FieldList" Source="{Binding DB.Fields}" CollectionViewType="{x:Type

Bind a WPF data grid to multiple data sources

孤街醉人 提交于 2019-12-07 13:13:23
问题 I have created a data grid in WPF and have 2 lists. I want to bind one column to one list and rest of the columns to another list. Can anyone please tell me how to do this? Thanks 回答1: Basically, You cant. The datagrid is an ItemsControl which has one ItemsSource property. What i would do is build a view model which is a composite object that contains one of each of the items (from the two lists). then you could bind to a collection of these. public class CompositeItem{ public Object

how to combine multiple header in wpf datagrid

爷,独闯天下 提交于 2019-12-07 11:57:11
问题 I want to Combine these two column "Stakes" and "Game". I want to combine two column into one column using wpf datagrid. My DataGrid is as Follow.![enter image description here][2] ![enter image description here][3] <DataGrid.CellStyle> <Style TargetType="{x:Type DataGridCell}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="Effect"> <Setter.Value> <DropShadowEffect BlurRadius="0" Color="#FF000000" Direction="-60" Opacity="0.32" ShadowDepth="1"/> </Setter.Value> <