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

Datagrid binding in WPF

PLEASE do not use object as a class name: public class MyObject //better to choose an appropriate name { string id; DateTime date; public string ID { get { return id; } set { id = value; } } public DateTime Date { get { return date; } set { date = value; } } … Read more

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

Select multiple items from a DataGrid in an MVVM WPF project

You can simply add a custom dependency property to do this: public class CustomDataGrid : DataGrid { public CustomDataGrid () { this.SelectionChanged += CustomDataGrid_SelectionChanged; } void CustomDataGrid_SelectionChanged (object sender, SelectionChangedEventArgs e) { this.SelectedItemsList = this.SelectedItems; } #region SelectedItemsList public IList SelectedItemsList { get { return (IList)GetValue (SelectedItemsListProperty); } set { SetValue (SelectedItemsListProperty, value); } } … Read more

programmatically add column & rows to WPF Datagrid

To programatically add a row: DataGrid.Items.Add(new DataItem()); To programatically add a column: DataGridTextColumn textColumn = new DataGridTextColumn(); textColumn.Header = “First Name”; textColumn.Binding = new Binding(“FirstName”); dataGrid.Columns.Add(textColumn); Check out this post on the WPF DataGrid discussion board for more information.