wpfdatagrid

Show RowDetails on double-click in WPF DataGrid

时间秒杀一切 提交于 2019-12-29 05:56:50
问题 At the moment my DataGrid shows the RowDetails when i click a row. But I want to show the RowDetails only on Double-click. Any ideas for solving this problem? Thank you! 回答1: e.g. <DataGrid RowDetailsVisibilityMode="Collapsed"> <DataGrid.RowStyle> <Style TargetType="{x:Type DataGridRow}"> <EventSetter Event="MouseDoubleClick" Handler="RowDoubleClick"/> </Style> </DataGrid.RowStyle> </DataGrid> private void RowDoubleClick(object sender, RoutedEventArgs e) { var row = (DataGridRow)sender; row

WPF ScrollViewer around DataGrid affects column width

拈花ヽ惹草 提交于 2019-12-28 04:07:08
问题 I have a problem with a ScrollViewer that I use to scroll a user control that contains a data grid. Without the scroll viewer the columns fill the data grid as I want but when adding a scroll viewer the columns shrink to ~15px. I was able to simplify my layout and can still reproduce this behaviour. When binding the datagrid width to another control the columns have their normal with, but that has unsuprisingly the same effect as a fixed width on the datagrid. I guess I'm not the first one

DataGridTextColumn Visibility Binding

家住魔仙堡 提交于 2019-12-28 02:05:03
问题 I'm trying to bind column visibility to that of another element like this: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> </Window.Resources> <StackPanel> <CheckBox x:Name="chkColumnVisible" Content="Show column" /> <DataGrid x:Name="MyDataGrid

Syntax error: Missing operand after 'Student' operator

混江龙づ霸主 提交于 2019-12-25 18:45:31
问题 This is the code I have: private void btnSearch_Click(object sender, RoutedEventArgs e) { using (SqlConnection sc = new SqlConnection(sConn)) { sc.Open(); string SearchFor = txtSearch.Text; using (SqlDataAdapter adapter = new SqlDataAdapter()) { DataTable dt = new DataTable(); grdData.ItemsSource = dt.DefaultView.RowFilter = string.Concat("SELECT * FROM Student WHERE Forename LIKE '%", SearchFor, "%'"); } When I run the code I get: "Syntax error: Missing operand after 'Student' operator." I'm

How to obtain row index and assign it to observable collection property of datagrid

天涯浪子 提交于 2019-12-25 16:42:22
问题 Basically, I have a DataGrid inside a DataGrid: <DataGrid ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" AutomationProperties.AutomationId="sCGridSelectedBasketItems" HeadersVisibility="Row" Height="{Binding ElementName=itemsgrid,Path=ActualHeight}" Grid.Row="1" RowDetailsVisibilityMode="Visible" CanUserAddRows="false" VerticalAlignment="Top" AutoGenerateColumns="False" SelectedItem="{Binding SelectedBasketItem}" ItemsSource="{Binding

Change datagrid selected row color programatically using wpf?

旧巷老猫 提交于 2019-12-25 09:28:00
问题 I want to change the selected row color dynamically in code behind. I'm using Visual Studio 2008. Can anyone help to do this? 回答1: Dim selectedItem As New Style(GetType(DataGridCell)) Dim triggerIsSelected As New Trigger() With {.[Property] = DataGridCell.IsSelectedProperty, .Value = True} triggerIsSelected.Setters.Add(New Setter(DataGridCell.BackgroundProperty, System.Windows.Media.Color.Red)) selectedItem.Triggers.Add(triggerIsSelected) Datagrid1.CellStyle = selectedItem 来源: https:/

DataGrid causes BeginEdit() method to run twice

风格不统一 提交于 2019-12-25 09:09:02
问题 I have implemented IEditableObject for my ViewModel and the below controls are bound to it. Now when the first time I fire up the Window containing these controls, the BeginEdit() method runs and backs up the variables. My problem is this: When I start editing the DataGrid again the BeginEdit() method runs and saves the changes to my already backed up variables! This ruins the purpose of the BeginEdit() and CancelEdit() . Now if I choose to cancel the Window, I won't have the original data.

DataGrid causes BeginEdit() method to run twice

假如想象 提交于 2019-12-25 09:07:53
问题 I have implemented IEditableObject for my ViewModel and the below controls are bound to it. Now when the first time I fire up the Window containing these controls, the BeginEdit() method runs and backs up the variables. My problem is this: When I start editing the DataGrid again the BeginEdit() method runs and saves the changes to my already backed up variables! This ruins the purpose of the BeginEdit() and CancelEdit() . Now if I choose to cancel the Window, I won't have the original data.

How to get Object type bound to DataGrid

二次信任 提交于 2019-12-25 06:23:43
问题 I have a DataGrid that is bound to ObservableCollection. What I am wondering is: without resorting to looking at an item and retrieving the object type, can I somehow use the actual DataGrid object and the ItemSource to find the type of objects? So if I have the following: DataGrid dg = DataGridObject as DataGrid; Console.WriteLine("binding5=" + dg.ItemsSource.GetType()); output = System.Collections.ObjectModel.ObservableCollection`1[UserManagement.UserViewModel] Can I extract UserManagement

How to get Object type bound to DataGrid

喜你入骨 提交于 2019-12-25 06:23:26
问题 I have a DataGrid that is bound to ObservableCollection. What I am wondering is: without resorting to looking at an item and retrieving the object type, can I somehow use the actual DataGrid object and the ItemSource to find the type of objects? So if I have the following: DataGrid dg = DataGridObject as DataGrid; Console.WriteLine("binding5=" + dg.ItemsSource.GetType()); output = System.Collections.ObjectModel.ObservableCollection`1[UserManagement.UserViewModel] Can I extract UserManagement