datagrid

How can I set the width of a DataGridColumn to fit contents (“Auto”), but completely fill the available space for the DataGrid in MVVM?

大憨熊 提交于 2019-12-29 11:36:26
问题 I have a WPF DataGrid that contains some data. I would like to set the width of the columns such that the content fits in and never gets cropped (instead, a horizontal scroll bar should become visible). Additionally, I want the DataGrid to fill the whole place available (I am working with a DockPanel ). I am using the following code (simplified): <DataGrid ItemsSource="{Binding Table}"> <DataGrid.Columns> <DataGridTextColumn MinWidth="100" Width="Auto" Header="Column 1" Binding="{Binding

Hide Datagrid Column based on its Property name

安稳与你 提交于 2019-12-29 09:17:10
问题 I have a DataGrid defined as follows : <DataGrid Name="dtMydatagrid" Margin="10,10,10,10" RowHeight="20" AutoGenerateColumns="True" ItemsSource="{Binding}" Height="auto" Width="auto"> <DataGrid.Columns> <DataGridTemplateColumn Header=""> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBox x:Name="TXT" Background="Transparent" Width="15" IsReadOnly="True" Visibility="Hidden" Margin="0,0,0,0"/> <DataTemplate.Triggers> <DataTrigger Binding="{Binding Path=IsBKM}" Value="true"> <Setter

GWT: DataGrid - set height 100% not rendering properly

ⅰ亾dé卋堺 提交于 2019-12-29 08:01:29
问题 I am working with layout panels and datagrid. When I set the datagrid height to 100%, Grid is not rendering. My panel hierarchy looks like the following image Am I doing it properly or I messed up the panel hierarchy??? Parent panel is the simple layout panel, inside that I have split layout panel -> scrollpanel -> datagrid 回答1: DataGrid requires to be put in a LayoutPanel or Panel that implements the ProvidesResize interface to be visible. ScrollPanel implements that interface. Furthermore

C#: WPF datagrid and xml file

萝らか妹 提交于 2019-12-29 07:12:11
问题 How can I read a xml file using a class and populate it on a datagrid? The datagrid should have validation capabilities? Xml file: <?xml version='1.0'?> <Data> <Book> <Author>John Doe</Author> <Title>Straight Track Demo</Title> <Version>1</Version> </Book> </Data> 回答1: There are a couple of ways you can load up a DataGrid with XML (there are others as well): Using an XmlDataProvider Reading the XML in from the code-behind Here's a very crude sample that uses both methods. XAML <Window x:Class

WPF add datagrid image column possible?

天大地大妈咪最大 提交于 2019-12-29 06:51:11
问题 Using C#.Net 4.5, Visual Studio 2012 Ulti, WPF. I've got some old win-forms code that i wanted to do in this new WPF app. code is the following: DataGridViewImageCell pNew = new DataGridViewImageCell(); ParetoGrid.Columns.Add(new DataGridViewImageColumn() { CellTemplate = pNew, FillWeight = 1, HeaderText = "pNew", Name = "pNew", Width = 30 }); ParetoGrid.Columns["pNew"].DisplayIndex = 18; 3 lines of code to add a column that can handle images. In WPF I've seen its a bit different. Do i need

How to set background of a datagrid cell during AutoGeneratingColumn event depending on its value?

不羁岁月 提交于 2019-12-29 06:10:34
问题 I'm still fighting with manipulation of cell backgrounds so I'm asking a new question. A user "H.B." wrote that I can actually set the cell style during the AutoGeneratingColumn event - Change DataGrid cell colour based on values. The problem is that I'm not sure how to do it. What I want: Set different background colours for each cell depending on its value. If the value is null I also want it not to be clickable (focusable I guess). What I have / I'm trying to do: private void mydatagrid

WPF DataGrid CellEditEnding - DataSet Not Updating Till Row Lost Focus

怎甘沉沦 提交于 2019-12-29 06:04:12
问题 I need to be able to update values of a dataset once a cell loses focus from editing. I know when the cell loses focus (CellEditEnding), but problem is, the actual updating of it's context item does not occur till focus on that row actually occurs. This becomes a huge issue when there is only one item left, since it may never lose focus. How do I make sure that each time a column edit is complete (CellEditEnding), the actual context for that row is updated at that point (not just when the row

WPF DataGrid CellEditEnding - DataSet Not Updating Till Row Lost Focus

99封情书 提交于 2019-12-29 06:03:40
问题 I need to be able to update values of a dataset once a cell loses focus from editing. I know when the cell loses focus (CellEditEnding), but problem is, the actual updating of it's context item does not occur till focus on that row actually occurs. This becomes a huge issue when there is only one item left, since it may never lose focus. How do I make sure that each time a column edit is complete (CellEditEnding), the actual context for that row is updated at that point (not just when the row

WPF: Dictionary<int, List<string>> in DataGrid

别来无恙 提交于 2019-12-28 18:53:08
问题 I have a Dictionary<int, List<string>> . Each ID(int) has a corresponding dynamic list of names( List<string> ). This is the expected output in Datagrid. ID | Name | Name | Name 1 Ash Tina Kara 2 Kc 3 Star Lara How do I achieve this? 回答1: <DataGrid x:Name="dg" ItemsSource="{Binding Dic}" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn Header="id" Binding="{Binding Key}"/> <DataGridTextColumn Header="Name" Binding="{Binding Value[0]}"/> <DataGridTextColumn Header="Name"

Tag Property in WPF DataGrid Column

∥☆過路亽.° 提交于 2019-12-28 18:44:14
问题 I need to save an string inside a Datagrid Column which differs from the Header. This is needed because I generate a Datagrid dynamically and want to translate the Column Headers while generating them. Then I bind the whole XAML to a ContentControl. No problem till here... But I want to reorder and resize the columns, so I need to lookup them afterwoods. For this I need the original (not translated) ColumnHeader. In my opinion a Tag property of the column would solve this problem, but there