wpfdatagrid

WPF 4 DataGrid: Getting the Row Number into the RowHeader

五迷三道 提交于 2019-11-27 11:57:25
I am looking to get the row number into the RowHeader of the WPF 4 DataGrid so it has an Excel-like column for the row numbers of the DataGrid. The solution I've seen out there on the web suggests adding an index field to the business objects. This isn't really an option because the DataGrid will be getting resorted a lot and we don't want to have to keep track of changing these index fields constantly. Thanks a lot One way is to add them in the LoadingRow event for the DataGrid . <DataGrid Name="DataGrid" LoadingRow="DataGrid_LoadingRow" ... /> void DataGrid_LoadingRow(object sender,

WPF DataGrid : CanContentScroll property causing odd behavior

☆樱花仙子☆ 提交于 2019-11-27 11:36:58
i have a solution where i generate a DataGrid (or multiple instances) based on user criteria.. each grid keeps receiving data as it comes in via ObservableCollection the problem i had, was that the scroll acted weird. It was choppy, and scrollbar would resize it self while scrolling. than i found.. CanContentScroll property! It completely fixes the weird scrolling behavior bringing me temporary bliss and happiness. however, it causes 2 unfortunate side effects. whenever i re-create grid instances and bind them to my observable collection, it freezes my entire window for 5 seconds. when my grid

WPF DataGrid: how do I stop auto scrolling when a cell is clicked?

萝らか妹 提交于 2019-11-27 11:13:18
问题 Problem: If my DataGrid is not entirely visible (horizontal & vertical scrollbars are showing) and I click on one of my cells that is partially visible, the grid auto-scrolls to bring that cell into view. I don't want this to happen . I've tried playing around with RequestBringIntoView , like this: private void DataGrid_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e) { e.Handled = true; } But that does nothing. Things I've tried: My cells are custom UserControls ; I tried

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

▼魔方 西西 提交于 2019-11-27 11:10:51
问题 How to change column header's background color when using WPF datagrid? Need to modify xaml directly? 回答1: 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> 回答2: Use this: <windows.Resources> <LinearGradientBrush x:Key="HeaderBrush" StartPoint="0.5,0"

How to refresh datagrid in WPF

[亡魂溺海] 提交于 2019-11-27 10:33:41
问题 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 ? 回答1: Reload the datasource of your grid after the update myGrid.ItemsSource = null; myGrid.ItemsSource = myDataSource; 回答2: Try mydatagrid.Items.Refresh() 回答3: From MSDN -

How do I add multiple images in StackPanel WPF from Folder?

六眼飞鱼酱① 提交于 2019-11-27 09:23:09
I want to give folder path and from that folder path If That folder contains 3 images I want to display those 3 images into StackPanel WPF Form I tried something like below which works fine for one image but how can load all the images from given folder? <Window x:Class="wpfBug.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300" Loaded="Window_Loaded"> <StackPanel Name="sp"> </StackPanel> </Window> private void Window_Loaded(object sender, RoutedEventArgs e) { Image i = new

.Net v4 DataGridTextColumn.IsReadOnly seems to be faulty

拟墨画扇 提交于 2019-11-27 08:51:10
If I create a binding to the IsReadOnly property of the DataGridTextColumn , it does not actualize. If I set it through markup, it works. <DataGridTextColumn IsReadOnly="{Binding IsReferenceInactive}"/> <!-- NOP --> <DataGridTextColumn IsReadOnly="True"/> <!-- Works as expected, cell is r/o --> The IsReferenceInactive property is a DP and works fine (For testing purposes I've bound it to a checkbox, that worked) Is this a known limitation? Update Uups, other than I wrote, there is a message in the output window: System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or

DataGrid Row Background Based On Cell Value

此生再无相见时 提交于 2019-11-27 07:45:28
问题 I am currently working on a C# WPF datagrid. I have a DataGrid which has auto generated columns and the code connects to an SQLite Database and creates a dataset and then this dataset is set as the DataGrid ItemsSource. Below is the code with the XAML of the DataGrid <DataGrid AutoGenerateColumns="True" Margin="12,71,12,32" Name="tblLog" ColumnWidth="*" CanUserResizeRows="False" AreRowDetailsFrozen="False" CanUserAddRows="True" CanUserDeleteRows="True" IsReadOnly="True" MouseDoubleClick=

How to convert DataGrid to dataTable

空扰寡人 提交于 2019-11-27 07:43:26
问题 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 回答1: 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 = (

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

白昼怎懂夜的黑 提交于 2019-11-27 07:20:51
问题 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! 回答1: This will rotate the whole ColumnHeaderCell: <DataGrid.ColumnHeaderStyle> <Style TargetType="{x:Type DataGridColumnHeader}"> <Setter Property="LayoutTransform