Date formatting in WPF datagrid

Don`t forget to use DataGrid.Columns, all columns must be inside that collection. In my project I format date a little bit differently: <tk:DataGrid> <tk:DataGrid.Columns> <tk:DataGridTextColumn Binding=”{Binding StartDate, StringFormat=\{0:dd.MM.yy HH:mm:ss\}}” /> </tk:DataGrid.Columns> </tk:DataGrid> With AutoGenerateColumns you won`t be able to contol formatting as DataGird will add its own columns.

WPF datagrid header text binding

This is the easy way to bind the DataGridTextColumn header to the data context: <DataGrid x:Name=”summaryGrid” Grid.Row=”3″ AutoGenerateColumns=”False” IsReadOnly=”True” CanUserAddRows=”False”> <DataGrid.Columns> <DataGridTextColumn Header=”Hard Coded Title” Width=”*”/> <DataGridTextColumn Width=”100″> <DataGridTextColumn.Header> <TextBlock Text=”{Binding DataContext.SecondColumnTitle, RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}}”/> </DataGridTextColumn.Header> </DataGridTextColumn> <DataGridTextColumn Width=”150″> <DataGridTextColumn.Header> <TextBlock Text=”{Binding DataContext.ThirdColumnTitle, RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}}”/> </DataGridTextColumn.Header> </DataGridTextColumn> </DataGrid.Columns> </DataGrid> You will obviously need to … Read more

WPF Datagrid set selected row

My code iterates through cells of the datagrid‘s first column and checks if cell content equals to the textbox.text value and selects the row. for (int i = 0; i < dataGrid.Items.Count; i++) { DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(i); TextBlock cellContent = dataGrid.Columns[0].GetCellContent(row) as TextBlock; if (cellContent != null && cellContent.Text.Equals(textBox1.Text)) { object item = dataGrid.Items[i]; … Read more

How to perform Single click checkbox selection in WPF DataGrid?

For single click DataGrid checkbox you can just put regular checkbox control inside DataGridTemplateColumn and set UpdateSourceTrigger=PropertyChanged. <DataGridTemplateColumn.CellTemplate> <DataTemplate> <CheckBox IsChecked=”{Binding Path=IsSelected, UpdateSourceTrigger=PropertyChanged}” /> </DataTemplate> </DataGridTemplateColumn.CellTemplate>

WPF horizontal DataGrid

I’ve done this earlier since we wanted to be able to use the same control for a DataGrid and a PropertyGrid. Alot of things have to be changed (like alignment, scrolling, positioning of sort-arrows etc.). There is way to much code to post the whole solution but this should get you started. This is an … Read more

How can I paginate a WPF DataGrid?

The code project article above is quite good for getting this done with ADO tables. While for most applications, it is likely to work great, and is easy to understand, there is a more “WPF-zen-like” way to do it as well, and that would be using CollectionViews. The advantage of using a CollectionView compared to … Read more

JavaScript data grid for millions of rows [closed]

(Disclaimer: I am the author of SlickGrid) UPDATE This has now been implemented in SlickGrid. Please see http://github.com/mleibman/SlickGrid/issues#issue/22 for an ongoing discussion on making SlickGrid work with larger numbers of rows. The problem is that SlickGrid does not virtualize the scrollbar itself – the scrollable area’s height is set to the total height of all … Read more

tech