wpfdatagrid

Datagrid selectedItem and databinding

拥有回忆 提交于 2019-12-06 02:46:21
问题 I have two datagrid displayed on my UI. When I select a particular row on datagrid 1, I would like to display the details of the datagrid 1 on datagrid 2. I am populating the datagrid data from a database. here is the two database table structure. Note: both the table are mapped by the personid in the database here is the code so far I have tried Baseclass.cs public class Baseclass { public event PropertyChangedEventHandler PropertyChanged; protected void SetProperty<T>(ref T member, T value,

How to set/reset Three-state checkbox value in WPF

天大地大妈咪最大 提交于 2019-12-06 02:10:53
问题 I have a datagrid whose one of the header column is Three-state checkbox. The celltemplate for that column contains two state checkbox + AllItems CheckBox - Item1 - Item2 - Item3 .. I wanted to use AllItems checkbox to select/unselect all items (item1,item2) which works fine. Next I wanted to set AllItems checkbox to intermediate state when not all items are selected/unselected. Similarly I wanted to set AllItems checkbox as checked/unchecked when all items get manually selected. Here is the

WPF DataGrid - How to move keyboard focus to newly added row after tab press

馋奶兔 提交于 2019-12-06 00:18:35
问题 WPF DataGrid add a new row if we press tab on last column of last row. But after adding the new row, the focus is moved to top row of the grid. How can we make sure that the focus is moved to the first column of new row? 回答1: You could try something like this.SelectRowCell(this.Items.Count - 1, 0); But I'm not sure if that will set the focus too. If not then try the following: DataGridCell cell = this.GetCell(this.Items.Count - 1, 0); if (cell != null) { cell.Focus(); } 来源: https:/

C# Load CSV into DataGrid

与世无争的帅哥 提交于 2019-12-05 23:37:48
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 a System . Windows . Controls . DataGrid UPDATE So I tried this: DataTable table = CSVReader

Wpf DataGrid hide complete row through DataBinding

拜拜、爱过 提交于 2019-12-05 22:37:21
问题 Is there a possiblity to hide DataGrid-rows through DataBinding: If I have items of a BO or a ViewModel that have a visibilty-property, is there a possibility to declare a binding so that the row will be hidden if the property is set to invisible and vice versa? 回答1: It should be possible to do it via RowStyle . Something like this: <DataGrid> <DataGrid.RowStyle> <Style TargetType="DataGridRow"> <Setter Property="Visibility" Value="{Binding Visibility}" /> </Style> </DataGrid.RowStyle> <

Style first row in a WPF Datagrid

浪子不回头ぞ 提交于 2019-12-05 22:30:13
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 code behind but couldn't get it to work. It seems like something that out to be fairly simple but I

How do I load a DataGrid with data from a database using WPF and MVVM?

给你一囗甜甜゛ 提交于 2019-12-05 21:53:02
I am a complete newbie to WPF and MVVM so I apologise in advance if this query is quite simple. I've searched online and havent been able to find anything which fits my requirements. Hense why I'm here! I am currently trying to implement a table of data queried from a database using LINQ. This is the query I run: DataContext connection = new DataContext(); var getTripInformation = from m in connection.tblTrips where m.TripDate > DateTime.Today select new { m.TripID, m.TripName, m.TripDate, m.ClosingDate, m.PricePerAdult, m.PricePerChild, m.Status }; Which fills my var with the relevant

how to combine multiple header in wpf datagrid

北城以北 提交于 2019-12-05 20:29:20
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> </Setter> <Setter Property="Margin" Value="10,0,0,0" /> <Setter Property="VerticalContentAlignment" Value=

Implement “drag and fill” functionality in WPF datagrid

旧巷老猫 提交于 2019-12-05 18:32:10
We are developing an app that utilises a data grid. Most of the grid's functionality will be fairly standard stuff - styling cells, in-cell editing, sorting, etc. However one requirement is to provide "drag and fill" functionality, like Excel. This is where you select one or more cells inside a row, which then get a thick border drawn around them. The border has a small square on its bottom-right corner, and when you drag this down Excel copies the selected cell values to the rows below. This sounds like a frightening thing to try and implement using the .Net WPF data grid (and no commercial

Cannot create an instance of “MainViewModel”

北战南征 提交于 2019-12-05 17:44:44
I am creating a simple WPFapplication for implementing Databinding a Datagrid to database using Observable collection (following MVVM pattern). App.xaml.cs class public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var mainWindow = new MainWindow(); var viewModel = new MainViewModel(); mainWindow.Show(); } } when I try to bind it to my XAML I have the following error raised : Cannnot create an instance of "MainViewModel" XAML code : <Window x:Class="MVVM_DemoAppl.Views.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml