xceedsoftware / wpftoolkit

All the controls missing in WPF. Over 1 million downloads.
Other
3.9k stars 878 forks source link

Not able to select all row of Datagrid #742

Open xceedsoftware opened 7 years ago

xceedsoftware commented 7 years ago

ashu_avni[CodePlex]
Can't able to select all row by Ctrl+A ,there are some rows which are missing from selection when i press Ctrl+A in datagrid. Any suggestion

xceedsoftware commented 7 years ago

ashu_avni[CodePlex]
Thanks for your valuable suggestion,problem has been solved. Error generated by below code block my:DataGrid.RowStyle Style TargetType={x:Type my:DataGridRow} Setter Property=IsSelected Value={Binding IsSelected}/ /Style /my:DataGrid.RowStyle Now i am using data grid SelectedItems property on selection changed event.

xceedsoftware commented 7 years ago

BoucherS[CodePlex]
Hi,

Isn't what you are doing ? From the code snippet you posted at the beginning of this post, I believed a DataGrid deriving from DataGridControl, a DataGridRow deriving from DataRow and a DataGridTextColumn deriving from Column where defined.

DataGridControl, DataRow and Column are the Core classes.

If you instanciate a DataGridControl, without creating your own classes Row, Colum, DataGrid, you should be able to select all rows. So if you create your own DataGrid, Row and Column, make sure you don't bypass this functionality.

Can you send complete sample if you still see this problem after your tests ?

xceedsoftware commented 7 years ago

ashu_avni[CodePlex]
So should I create my own DataGridRow ,DataGridTextColumn or DataGrid classes? Which are inherited by core control and override those classes to solve this problem as you have mentioned into your code.

xceedsoftware commented 7 years ago

BoucherS[CodePlex]
You should not modify the core controls ( DataGridControl, DataRow, Column... ) since the SelectAll of rows should be working by default. I believe the problem is more in the DataGridRow ,DataGridTextColumn or DataGrid or others user classes.

xceedsoftware commented 7 years ago

ashu_avni[CodePlex]
Is there any option not to change in core control(DataGrid) and handle this issue as per MVVM approach?

xceedsoftware commented 7 years ago

BoucherS[CodePlex]
Yes, try in every classes. Does the code I copied works for you ?

xceedsoftware commented 7 years ago

ashu_avni[CodePlex]
I used your approach and commented portion of code to isolate Ctrl+A feature, but still facing same issue. Should i also change in Datagrid and its supporting classes i.e.(DataGridRow ,DataGridTextColumn)?

xceedsoftware commented 7 years ago

BoucherS[CodePlex]
Hi,

The problem has to be in your implementation. Try commeting portion of code to isolate the problem with Ctrl+A not selecting all rows.

I try your code (with some modifications) and Ctrl+A is selecting all rows.

Here's my code :

my:DataGrid x:Name=GridX Background=White ItemsSource={Binding Path=Xdata}
SelectedItem={Binding SelectedX} IsReadOnly=True AutoGenerateColumns=False HeadersVisibility=Column CanUserResizeColumns=True SelectionMode=Extended Margin=6,43,0,0
HorizontalGridLinesBrush=LightGray VerticalGridLinesBrush=LightGray my:DataGrid.RowStyle Style TargetType={x:Type my:DataGridRow} Setter Property=IsSelected Value={Binding IsSelected}/ /Style /my:DataGrid.RowStyle my:DataGrid.Columns my:DataGridTextColumn Header=S.No Binding={Binding Path=SequenceNumber}/my:DataGridTextColumn my:DataGridTextColumn Header=Name Binding={Binding Path=Name}/my:DataGridTextColumn my:DataGridTextColumn Header=Notes Binding={Binding Path=Description}/my:DataGridTextColumn /my:DataGrid.Columns /my:DataGrid

public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.Xdata = new ObservableCollectionUserItem() { new UserItem() { SequenceNumber = 0, Name = Bob, Description = Data1}, new UserItem() { SequenceNumber = 1, Name = Brian, Description = Data2}, new UserItem() { SequenceNumber = 2, Name = Alex, Description = Data3}, new UserItem() { SequenceNumber = 3, Name = Tom, Description = Data4}, new UserItem() { SequenceNumber = 4, Name = Jerry, Description = Data5}, }; GridX.DataContext = this; }

public ObservableCollectionUserItem Xdata { get; set; }

public UserItem SelectedX { get; set; } }

public class UserItem { public int SequenceNumber { get; set; }

public string Name { get; set; }

public string Description { get; set; } }

public class DataGrid : DataGridControl { public bool IsReadOnly { get { return this.ReadOnly; } set { this.ReadOnly = value; } }

public bool AutoGenerateColumns { get { return this.AutoCreateColumns; } set { this.AutoCreateColumns = value; } }

public string HeadersVisibility { get; set; }

public bool CanUserResizeColumns { get; set; }

public Brush HorizontalGridLinesBrush { get; set; }

public Brush VerticalGridLinesBrush { get; set; }

public Style RowStyle { get; set; } }

public class DataGridTextColumn : Column { public string Header { get { return (string)this.Title; } set { this.Title = value; } }

public Binding Binding { set { this.FieldName = value.Path.Path; DataGridBindingInfo bindingInfo = new DataGridBindingInfo(); bindingInfo.Path = value.Path; this.DisplayMemberBindingInfo = bindingInfo; } } }

public class DataGridRow : DataRow { public static new readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(IsSelected, typeof(bool), typeof(DataGridRow) ); public new bool IsSelected { get { return (bool)this.GetValue(DataGridRow.IsSelectedProperty); } set { this.SetValue(DataGridRow.IsSelectedProperty, value); } } }

xceedsoftware commented 7 years ago

ashu_avni[CodePlex]
I tried same dll with new app it works fine but when i using it in my existing application its not working properly. I used data grid control as per MVVM approach My code snippet: my:DataGrid Name=GridX Grid.Row=0 Background=White ItemsSource={Binding Path=Xdata} SelectedItem={Binding SelectedX} IsReadOnly=True AutoGenerateColumns=False HeadersVisibility=Column CanUserResizeColumns=True helpers:MouseDoubleClickBehavior.DoubleClickCommand={Binding Path=EditXCommand} SelectionMode=Extended Margin=6,43,0,0 HorizontalGridLinesBrush=LightGray VerticalGridLinesBrush=LightGray i:Interaction.Triggers i:EventTrigger EventName=SelectionChanged GalaSoft_MvvmLight_Command:EventToCommand Command={Binding Path=BulkDeleteXCommand, Mode=OneWay}/ /i:EventTrigger /i:Interaction.Triggers my:DataGrid.RowStyle Style TargetType={x:Type my:DataGridRow} Setter Property=IsSelected Value={Binding IsSelected}/ !-- or the IsCheckedm property -- /Style /my:DataGrid.RowStyle my:DataGrid.Columns my:DataGridTextColumn Header=S.No Binding={Binding Path=SequenceNumber}/my:DataGridTextColumn my:DataGridTextColumn Header=Name Binding={Binding Path=Name}/my:DataGridTextColumn my:DataGridTextColumn Header=Notes Binding={Binding Path=Description}/my:DataGridTextColumn /my:DataGrid.Columns /my:DataGrid

I also tried key down event on xaml but didn't succeed Any suggestion pls

xceedsoftware commented 7 years ago

BoucherS[CodePlex]
Hi,

Can you provide a sample App ?

When I try the Live Explorer App available here : https://wpftoolkit.codeplex.com/ In the sample Data/DataGrid

I can select all rows by using Ctrl+A.