wpfdatagrid

WPF: How do I set the focus on a datagrid to a specific row?

安稳与你 提交于 2019-12-01 19:38:41
问题 I would like to set the focus on the first row of a data grid. This is what I have so far: Keyboard.Focus(ResultsGrid) If result.Count > 0 Then ResultsGrid.SelectedIndex = 0 End If This will set the focus to the datagrid, but not the row itself. 回答1: After selecting the row you will have to set the focus on the row in the following way: ResultsGrid.SelectedIndex = index; DataGridRow row = (DataGridRow)ResultsGrid.ItemContainerGenerator.ContainerFromIndex(index); row.MoveFocus(new

How do I get around this lambda expression outer variable issue?

…衆ロ難τιáo~ 提交于 2019-12-01 18:28:16
I'm playing with PropertyDescriptor and ICustomTypeDescriptor ( still ) trying to bind a WPF DataGrid to an object, for which the data is stored in a Dictionary. Since if you pass WPF DataGrid a list of Dictionary objects it will auto generate columns based on the public properties of a dictionary (Comparer, Count, Keys and Values) my Person subclasses Dictionary and implements ICustomTypeDescriptor. ICustomTypeDescriptor defines a GetProperties method which returns a PropertyDescriptorCollection. PropertyDescriptor is abstract so you have to subclass it, I figured I'd have a constructor that

WPF: How do I set the focus on a datagrid to a specific row?

谁说胖子不能爱 提交于 2019-12-01 18:19:26
I would like to set the focus on the first row of a data grid. This is what I have so far: Keyboard.Focus(ResultsGrid) If result.Count > 0 Then ResultsGrid.SelectedIndex = 0 End If This will set the focus to the datagrid, but not the row itself. After selecting the row you will have to set the focus on the row in the following way: ResultsGrid.SelectedIndex = index; DataGridRow row = (DataGridRow)ResultsGrid.ItemContainerGenerator.ContainerFromIndex(index); row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); Try this: yourDataGrid.SelectedItem = yourDataGrid.Items[i]; 来源: https

WPF DataBinding Error: Cannot find source for binding with reference 'RelativeSource FindAncestor'

大憨熊 提交于 2019-12-01 16:17:14
I get the following errors from the code below... not sure why (and yes, it produces all 4 even though it's the same 2 repeated). Oh, and it doesn't produce the alternating rows effect, even though prior to these errors popping up the same code was working. System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.DataGrid', AncestorLevel='1''. BindingExpression:Path=AreRowDetailsFrozen; DataItem=null; target element is 'DataGridDetailsPresenter' (Name=''); target property is 'SelectiveScrollingOrientation'

WPF MVVMLight: Update DataGrid based on SelectedItem of another DataGrid

大城市里の小女人 提交于 2019-12-01 14:20:30
Developing a WPF app using MVVMLight . My Model consists of an Attribute class and a DataSet class with an ObservableCollection<Attribute> property named Attributes . My MainViewModel has a DataSet property. In my MainView which has it's DataContext set to MainViewModel I have two DataGrids . One has it's ItemsSource binded to DataSet.Attributes which works fine: <DataGrid CanUserAddRows="false" AutoGenerateColumns="false" ItemsSource="{Binding DataSet.Attributes}"> //some DataGrid columns here I want the second DataGrid to display some additional properties based on the SelectedItem of the

Get the multiple selected Row in data-grid in WPF?

旧时模样 提交于 2019-12-01 10:59:45
I want to get the multiple selection of data-grid in WPF, as my the business requirement I have a customer table in data grid which allows multiple selection and radio button (ALL, Selected, All but selected). If the selected or all but selected is clicked the I have to pull data only for those customers which are selected in the data- grid. Please advice solution to get multiple selected row of data grid. Thanks. I have got a solution for the above question, //CustomerDTO is the DTO class which has all the column names of Customer Table. //dgUsers is the data grid. List<CustomerDTO>

EditMode in DataGrid with single click via XAML triggers

旧街凉风 提交于 2019-12-01 10:55:30
问题 I have DataGrid, if I want edit value in cell I must perform double click for on this and cursor appear here (with one click it just select appropriate cell)..! May I make (via Xaml triggers) that with single click on cells they aren't just selected, but entered in EditMode at once and when I switch between cells with arrows they also enter in EditMode? Here my current revised code <Page.Resources> <grd:LenghthToVisibility x:Key="LenghthToVisibility"/> <grd:StringToSystemIconConverter x:Key=

WPF DataGridTemplateColumn Visibility Binding under MVVM

放肆的年华 提交于 2019-12-01 10:38:11
I have a DataGrid bound to an ICollectionView in my ViewModel. The DataGrid is inside a UserControl which is used in a few different data scenarios, some of which require certain DataGrid columns while others don't. I just want to bind the DataGridTemplateColumn's Visibility property to the inner label's Content property so if none of the rows contain a value, it will be hidden. I have a String to Visibility converter set, but can't figure out how to find the inner lable's Content property. <DataGridTemplateColumn Header="Groups" Width="*" CanUserSort="True" SortMemberPath="Groups" Visibility=

Sort WPF datagrid with integer appended with string

牧云@^-^@ 提交于 2019-12-01 10:35:45
I have a wpf datagrid. I assign ObservableCollection to it. DG1.DataContext = a; One of the columns is having values like following 1_A_B 12_A1_B 3_A2_B 10_A3_B 2_A4_B 15_A5_B i want to sort the datagrid using the first integer value like following 1_A_B 2_A4_B 3_A2_B 10_A3_B 12_A1_B 15_A5_B If i sort using this column, it is taking as string ascending like following(which is not i want) 1_A_B 10_A3_B 12_A1_B 15_A5_B 2_A4_B 3_A2_B I want to sort using the first integer value in above column The values 1_A_B , 12_A1_B etc will be contained within the property bound to that column. Let's call

Sort WPF datagrid with integer appended with string

我是研究僧i 提交于 2019-12-01 09:32:01
问题 I have a wpf datagrid. I assign ObservableCollection to it. DG1.DataContext = a; One of the columns is having values like following 1_A_B 12_A1_B 3_A2_B 10_A3_B 2_A4_B 15_A5_B i want to sort the datagrid using the first integer value like following 1_A_B 2_A4_B 3_A2_B 10_A3_B 12_A1_B 15_A5_B If i sort using this column, it is taking as string ascending like following(which is not i want) 1_A_B 10_A3_B 12_A1_B 15_A5_B 2_A4_B 3_A2_B I want to sort using the first integer value in above column