wpfdatagrid

How to add a right click context menu to Column Header for a WPF 4 DataGrid?

空扰寡人 提交于 2019-11-29 01:41:21
I want the context menu for a DataGrid's column headers to be different than the rest of the cells. So using the regular ContextMenu property is not going to work. There is DataGrid.RowHeaderTemplate, but I can't find DataGrid.ColumnHeaderTemplate. Edit/Note: Columns are generated dynamically. WPF-it Target a common Style to all DataGridColumnHeaders: <DataGrid.Resources> <ContextMenu x:Key="DataGridColumnHeaderContextMenu" ...> </ContextMenu> <Style TargetType="{x:Type DataGridColumnHeader}"> <Setter Property="ContextMenu" Value="{StaticResource DataGridColumnHeaderContextMenu}" /> </Style> <

How to bind an 2D array bool[][] to a WPF DataGrid (one-way)?

ⅰ亾dé卋堺 提交于 2019-11-28 23:56:27
I have a matrix kind datagrid like this. this grid is designed entirely in XAML Now how to insert values into these datagridcell with 2 dimensional array ? the values which is needed to be inserted must be of bool datatype (either TRUE or FALSE). Any ideas ? Here is my approach for a MVVM scenario, using a converter which creates a DataView which can be bound to the grids ItemsSource . It's for a special Matrix datatype which holds doubles, but you'll be able to modify it yourself for your requirements: public class MatrixToDataViewConverter : IValueConverter { public object Convert(object

How Do I Hide wpf datagrid row selector

有些话、适合烂在心里 提交于 2019-11-28 21:43:40
问题 I'm using the WPF DataGrid control to show some details and a select button, and I don't need the gray selector column down the left-hand side. It's also ruining the beauty of my design. Is there a way to remove it, or how can I style it to match if not? 回答1: Use the RowHeaderWidth property: <my:DataGrid RowHeaderWidth="0" AutoGenerateColumns="False" Name="dataGrid1" /> Note that you can also specify a style or template for it also, should you decide you really do like it and want to keep it

How can I disable editing cells in a WPF Datagrid?

。_饼干妹妹 提交于 2019-11-28 20:41:35
问题 I'm constructing a datagrid in Windows Presentation Foundation, and I have a problem. When a user double-clicks on a cell in my datagrid, the cell goes into edit mode. I want to prevent that. Instead I want users to be able to select the full row - not edit values in it. How can I make it so that double-clicks select the full row instead of putting the clicked-on cell in edit mode? 回答1: The WPF DataGrid has an IsReadOnly property that you can set to True to ensure that users cannot edit your

How to change column header's background color when using WPF datagrid

自闭症网瘾萝莉.ら 提交于 2019-11-28 18:39:56
How to change column header's background color when using WPF datagrid? Need to modify xaml directly? Use a style with a setter targeted at DataGridColumnHeader: <DataGrid> <DataGrid.Resources> <Style BasedOn="{StaticResource {x:Type DataGridColumnHeader}}" TargetType="{x:Type DataGridColumnHeader}"> <Setter Property="Background" Value="Blue" /> </Style> </DataGrid.Resources> </DataGrid> Jeetendra negi Use this: <windows.Resources> <LinearGradientBrush x:Key="HeaderBrush" StartPoint="0.5,0" EndPoint="0.5,1"> <GradientStop Color="#FF6B8E95" Offset="0"/> <GradientStop Color="#FF14A7C1" Offset="1

How to refresh datagrid in WPF

你说的曾经没有我的故事 提交于 2019-11-28 17:54:50
My source is in a MySQL database, I've made an update command and now I need to refresh my DataGrid . MySqlCommand cmd = new MySqlCommand( "update request set status = " + StatusRequest(value) + " where id = " + rowView[0].ToString() + "", conn); MySqlDataReader myReader = cmd.ExecuteReader(); How do I refresh my DataGrid ? Reload the datasource of your grid after the update myGrid.ItemsSource = null; myGrid.ItemsSource = myDataSource; Try mydatagrid.Items.Refresh() From MSDN - CollectionViewSource.GetDefaultView(myGrid.ItemsSource).Refresh(); Bind you Datagrid to an ObservableCollection , and

How to convert DataGrid to dataTable

笑着哭i 提交于 2019-11-28 13:30:47
I want to copy all the datagrid records into datatable without using any loop. For Ex: Dim dt as New DataTable dt = Datagrid1.Items But this is not Working and giving an error message. My Development platform is Visual studio 2010 and language is WPF with vb.net 4.0 Rishap Gandhi This is the way to transfer all the records from DATAGRID to DATATABLE without using the LOOP. VB: Dim dt As New DataTable dt = CType(DataGrid1.ItemsSource, DataView).ToTable C#: DataTable dt = new DataTable(); dt = ((DataView)DataGrid1.ItemsSource).ToTable(); It depends how the datagrid is populated. If the

How to set vertical text in the column headers of WPF DataGrid?

瘦欲@ 提交于 2019-11-28 12:58:16
Well, actually rotated -90 degrees from horizontal is what I mean. I need to do this because the text for the header is quite long but the cell value is short, and I want to fit a lot of columns on the screen. Is it possible to do this easily or do I need to learn about resources and templates first? I don't mind a "hack" solution! This will rotate the whole ColumnHeaderCell: <DataGrid.ColumnHeaderStyle> <Style TargetType="{x:Type DataGridColumnHeader}"> <Setter Property="LayoutTransform"> <Setter.Value> <RotateTransform Angle="270" /> </Setter.Value> </Setter> </Style> </DataGrid

Using WPF DataGridComboBoxColumn with MVVM - Binding to Property in ViewModel

流过昼夜 提交于 2019-11-28 12:05:02
I'm using the excellent MVVM Light Toolkit. My ViewModel exposes: public const string CourtCodesTypeCourtPropertyName = "CourtCodesTypeCourt"; private List<CourtType> _courtCodesTypes = new List<CourtType>(); public List<CourtType> CourtCodesTypeCourt { get { return _courtCodesTypes; } set { if (_courtCodesTypes == value) { return; } var oldValue = _courtCodesTypes; _courtCodesTypes = value; // Update bindings and broadcast change using GalaSoft.MvvmLight.Messenging RaisePropertyChanged(CourtCodesTypeCourtPropertyName, oldValue, value, true); } } public const string CourtCodesPropertyName =

WpfToolkit DataGrid: Highlight modified rows

有些话、适合烂在心里 提交于 2019-11-28 09:38:55
问题 Is there a way to highlight all the modified rows on a DataGrid? Since the grid is bound to a System.Data.DataTable I figured I might be able to bind the colour of each row to it's RowState (example below), but that doesn't seem to work. Any ideas? xmlns:data="clr-namespace:System.Data;assembly=System.Data" <Style x:Key="DataGridRowStyle" TargetType="{x:Type toolkit:DataGridRow}"> <Style.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter Property="Background" Value="Blue" /> <