Posts

Showing posts with the label Observable Collection

Donate

WPF DataGrid Excel Comment Indicator

Image
Here's how to add a comment indicator to a DataGridCell similar to an Excel functionality using MultiValueConverter. See codefiles and screenshot below. XAML 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 <Window x:Class= "WPFExcelCommentIndicator.DataGridCellCommentIndicator" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml" xmlns:src= "clr-namespace:WPFExcelCommentIndicator" Title= "DataGridCellCommentIndicator" Height= "350" Width= "500" WindowStartupLocation= "CenterScreen" > <Window.Resources> <src:DataGridCellComment x:Key= "DataGridCellComment" /> <src:StudentList x:Key= "StudentListData" /> </W

WPF Add Or Delete Rows In A DataGrid Using Observable Collection

Image
Here's a simple way of adding/deleting WPF Datagrid rows using observable collection. XAML Code 1 2 3 4 5 6 7 8 <DataGrid AutoGenerateColumns= "False" ItemsSource= "{Binding}" Margin= "12,12,12,41" Name= "dataGrid1" CanUserResizeRows= "False" CommandManager.PreviewExecuted= "UserDataGrid_PreviewDeleteCommandHandler" RowEditEnding= "dataGrid1_RowEditEnding" RowHeaderWidth= "20" > <DataGrid.Columns> <DataGridTextColumn Binding= "{Binding UserName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header= "User name" Width= "230" > </DataGridTextColumn> <DataGridTextColumn Binding= "{Binding FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header= "First Name" Width= "245" > </DataGridTextColumn> </DataGrid.Columns> </DataGrid> C#

Change WPF DataGridCell Background Color Using IVMultiValueConverter

Image
In a post by codefornothing in which He demonstrate the use of IMultiValueConverter using DataTable: The WPF Datagrid and Me , I decided to create a similar post in which the binding source is of type collection (Observable Collection). I encountered a few issues like how to replace the Binding Path values from binding to a strongly type class instead of DataTable. To get things started, here are the snippets: Observable Class public class StudentList : ObservableCollection<Student> { public StudentList() { Add( new Student{ID = 1, Age = 29, Name = "Jerby" , Address= "Cebu" }); Add( new Student{ID = 2, Age = 28, Name = "Renz" , Address= "Cebu" }); Add( new Student{ID = 3, Age = 23, Name = "Aya" , Address= "Leyte" }); Add( new Student{ID = 4, Age = 33, Name = "Jeff" , Address= "Leyte" }); Add( new Student{ID = 5

Sort Observable Collection Object In WPF

The snippet below sorts the Observable Collection object which is scriptInfo using time_start which is a property of a strongly typed class. scriptInfo.OrderBy(i => i.time_start); Cheers!

Loop Through Datagrid In WPF (ItemSource Is Type Observable Collection)

Hello, Assuming the databinding source of WPF Datagrid is of type ObservableCollection, the code below will loop through the WPF DataGrid. var row = GetDataGridRows(dgScripts); foreach (DataGridRow r in row) { CScriptsInfo info = (CScriptsInfo)r.Item; if (info.prog_name.ToString().Contains(txtScriptName.Text.Trim().ToUpper())) { r.IsSelected = true ; } }

Donate