wpfdatagrid

Creating an AttachedProperty to hold positions for scrollbar markers

旧时模样 提交于 2019-12-06 14:53:07
问题 I have created slightly customized vertical scrollbar for my DataGrid. In it I have added an ItemsControl to hold positions of the selected items. Here is a mockup so far with hard-coded markers. Below is my customized vertical scrollbar template where the ItemsControl is placed with hard-coded marker values. <ControlTemplate x:Key="VertScrollBar" TargetType="{x:Type ScrollBar}"> <Grid> <Grid.RowDefinitions> <RowDefinition MaxHeight="18" /> <RowDefinition Height="0.00001*" /> <RowDefinition

Why does one of MY WPF DataGrids give the “'EditItem' is not allowed for this view” exception?

不羁岁月 提交于 2019-12-06 14:17:36
I have read all the Q&A I could find here and on the MS forums about this exception, and tried most of the suggestions that I understood, and a few others. It seems that this exception can come up for a wide range of causes. As with others, I have a WPF DataGrid bound to a collection, which throws this exception when one tries to edit one of the cells. They are set to be write-able, the collection is an ObservableCollection, I've implemented get and set handlers which send notification messages. The suggestions I haven't tried are the ones involving implementing IList's non-generic interface,

How to bind property name to which column is binded to pass as command parameter

*爱你&永不变心* 提交于 2019-12-06 14:01:03
问题 On each DataGridColumnHeader I have a button that I use to open a popup. As a parameter it sends the column's bound Property name to the ICommand in my ViewModel. This works well for any DataGridTextColumn however when it comes to a DataGridComboBoxColumn the structure is different. How would I solve this? <Button Command="{Binding DataContext.OpenFilterCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{Binding Column.Binding.Path.Path, RelativeSource=

Show “No record found” message on a WPF DataGrid when it's empty

心已入冬 提交于 2019-12-06 13:47:44
I'm trying to display a "No record found" Message in my WPF Datagrid I tried the solution from the same question here: Show "No record found" message on a WPF DataGrid when it's empty But so far I didn't find a way to add a empty line only when my ObservableCollection is empty. This is the code for my datagrid: <DataGrid DataContext="{Binding RelativeSource={RelativeSource AncestorType=Window}}" ItemsSource="{Binding CameraListObjCode}" AutoGenerateColumns="False" Height="145" HorizontalAlignment="Left" Margin="62,105,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="361" IsReadOnly="True">

WPF - fill data on data grid

谁说我不能喝 提交于 2019-12-06 12:10:08
I have the following code and I didnt find any way how to add the data from users to table .I want to do that dynamically . I have create WPF application and add Data Grid and button and I that when I click on the button see the data on the data grid ,how should I proceed? private void Button_Click(object sender, RoutedEventArgs e) { //get user data... DataTable dt = new DataTable("Users Info"); DataGrid.ItemsSource = dt.DefaultView; foreach (var user in users) { string firstName = user.Firstname; string lastName = user.Lastname; } The Xaml is: <Window xmlns="http://schemas.microsoft.com/winfx

two way wpf datagrid binding to database

℡╲_俬逩灬. 提交于 2019-12-06 08:39:39
问题 HI all, I want to bind WPF datagrid in two way. I had tried following XAML: <Grid> <my:DataGrid x:Name="dataGrid" AutoGenerateColumns="False" Margin="8"> <my:DataGrid.Columns> <my:DataGridTextColumn Header="Header" Binding="{Binding pCode}" IsReadOnly="True" /> <my:DataGridTextColumn Header="Header" Binding="{Binding pName}" IsReadOnly="True" /> <my:DataGridTextColumn Header="Header" Binding="{Binding pStock}" IsReadOnly="True" /> <my:DataGridTextColumn Header="Header" Binding="{Binding

How to change Text of TextBlock which is in DataTemplate of Row Details for each DataGrid Row Details?

半世苍凉 提交于 2019-12-06 07:17:03
问题 I have Datagrid which is clicking by mouse in each row is showing data grid row details. here is code, Microsoft.Windows.Controls.DataGridRow row = (Microsoft.Windows.Controls.DataGridRow)(DataGrid1.ItemContainerGenerator.ContainerFromItem(DataGrid1.SelectedItem)); DataGridDetailsPresenter presenter = FindVisualChild<DataGridDetailsPresenter>(row); DataTemplate template = presenter.ContentTemplate; TextBlock txt = (TextBlock)template.FindName("rowdetails", presenter); txt.Text = retString;

Datagrid template with rounded corners

跟風遠走 提交于 2019-12-06 05:11:02
I'm creating DataGrid template with rounded corners, but I faced with this problem: Bottom corners are out of the border bounds. How to solve this? I've read this article: http://diptimayapatra.wordpress.com/2010/06/28/rounded-corner-datagrid-in-wpf/ I need to do the same, but in Template. Here is my DataGrid Template Code: <Style TargetType="{x:Type DataGrid}"> <Setter Property="Background" Value="{StaticResource ControlContentBrush}"/> <Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected"/> <Setter Property="ScrollViewer.CanContentScroll" Value="true"/> <Setter Property=

How to get field that datagrid column is bound to?

佐手、 提交于 2019-12-06 03:27:09
In my xaml I have modified each column header to include a button. For the command parameter I would like to use the column's data field name, instead of the header content. E.g. Instead of "Job Title" which is what the header content is, I want "JOB_TITLE". For header content I would use: <Button Command="{Binding DataContext.OpenFilterCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="{TemplateBinding Content}"> How do I get the actual field name? If i assume it right you want binding property name to which column is binded to pass as command parameter to

Determine who has focus in WPF Window

好久不见. 提交于 2019-12-06 02:49:28
问题 We are using WPF and have a window derived from a DockingLibrary. This window has a grid with multiple items in it, one being a WPF datagrid. We are using the M-V-VM pattern. When this windown is created and shown, none of the rows in this datagrid are selected. We can set the row to display as highlighted by doing something like: SharedWindow.ShipmentWin.shipmentDataGrid.SelectedIndex = 0; This causes the first row in the datagrid to be shown as highlighted. But, and isn't there always one