WPF DataGrid sample: Add a preview ToolTip to a ScrollViewer
A customer was asking for a sample of a preview ToolTip on scrolling for the DataGrid and Ben Carter, one of our awesome Devs, wrote a sample here for any general ItemsControl. If you haven’t already, you can download the binaries and source for the DataGrid here. With Ben's sample I've put it to use in the DataGrid. Pretty much all the work has already been done by Ben's code, I just use the attached behavior he has defined. I have one DataGrid that has a preview ToolTip similar to his ListBox example and one DataGrid that has a preview ToolTip with the item count. I've also included a checkbox for changing the scrolling mode from live to defered (more on defered scrolling here). Check out the DataGrid sample here.
DataGrid_V1_ScrollPreviewSample.zip
Comments
Anonymous
August 25, 2008
PingBack from http://hoursfunnywallpaper.cn/?p=2916Anonymous
August 25, 2008
PingBack from http://housesfunnywallpaper.cn/?p=2366Anonymous
August 25, 2008
Hi Vince, a great thing! I am deeply impressed that dynamically selecting a picture in a cell is far less complicated than i feared it was ;) But I have some worries remaining: *) Can I somehow tell a DataGridComboboxColumn to show "Vanilla (organic production)" and to read/save "vanilla_organic" (for localization purposes, for example)? i.e. like the DisplayMemberPath/SelectedValuePath-Property of a standard ComboBox? *) Is it possible to tell my Column that it should display the DisplayName-Attribute Value of the Property of the Object it is bound to? (Sounds strange, I know, but would make a superb clean solution) Great work you do! AlexAnonymous
August 25, 2008
- DataGridComboBoxColumn.DataFieldTarget might be what you're looking for. There are actually some tricky things going on here so I'm actually going to do a post on this. stay tuned.
- I'm assuming you mean the ColumnHeader display name right? If you are doing auto-column generation you can do something like this: [DisplayName("PersonID")] public int Id { get { return id; } set { id = value; OnPropertyChanged("Id"); } } this.DataGrid_Standard.AutoGeneratingColumn += new EventHandler<DataGridAutoGeneratingColumnEventArgs>(DataGrid_Standard_AutoGeneratingColumn); void DataGrid_Standard_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) { e.Column.Header = (e.PropertyDescriptor as MemberDescriptor).DisplayName; } Then your headers will all take on the DisplayName attribute values.
- Anonymous
August 26, 2008
Hi, We are very much impressed by features of this datagrid. We are looking for more features like:
- Summary Footer
- Custom Formula in datagrid and footer
- Save Layout
- Extended Filter
- Export to excel, pdf, csv, xps
- Conditional Formatting
- drag and drop rows (within and from other grid)
- Merge cells in Header / Footer / Body. I would appreciate your reply. Regards, Sandeep
Anonymous
August 26, 2008
The comment has been removedAnonymous
August 26, 2008
Alex, I just wrote a post that may help with your first question. http://blogs.msdn.com/vinsibal/archive/2008/08/26/wpf-datagrid-working-with-datagridcomboboxcolumn.aspxAnonymous
August 29, 2008
As you might have heard, .NET Framework 3.5 SP1 and Visual Studio 2008 SP1 are out today! There are aAnonymous
August 29, 2008
Overview The DataGrid uses a set of DataGridColumns to describe how to display its data just like a GridViewAnonymous
September 19, 2008
In the v1 release (and CTP) of the WPF DataGrid there will be support for Clipboard.Copy but no supportAnonymous
September 19, 2008
Here is a short sample on how to create a tri-state sorting experience with the WPF DataGrid . In theAnonymous
September 19, 2008
There have been several questions on the WPF CodePlex discussion list relating to styling rows and columnsAnonymous
May 20, 2009
i need to drag column from postion to other in wpf datagrid.is it possibleAnonymous
May 21, 2009
vamsi, That functionality should be working by default. Have you tried it?Anonymous
June 12, 2009
Hi, I wonder if you can help me. I have a memory leak when refreshing the Data on a DataGFid, I'm guessing that I am not releasing something properly but I cannot see what it is. As a test I replaced your initilaization code with: public Window1() { InitializeComponent(); DataGrid_Standard.Columns.CollectionChanged += new NotifyCollectionChangedEventHandler(Columns_CollectionChanged); // update config bindings ICollectionView view = CollectionViewSource.GetDefaultView(DataGrid_Standard.ItemsSource); iecv = (IEditableCollectionView)view; this.NewItemPlaceholderPositionCB.DataContext = iecv; System.Timers.Timer t = new System.Timers.Timer(1000); t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed); t.Start(); } and added a handler of: void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //throw new NotImplementedException(); DataGrid_Standard.Dispatcher.Invoke((Action)delegate() { DataGrid_Standard.ItemsSource = new EditablePeople(20); }); } When you run this you can see the memory getting chewed up on each refresh. Do you have any pointer/suggestions to prevent this from happening? Thanks in advance for any help. SteveAnonymous
June 17, 2009
Hi Steve, I ran it through windbg and found that each Person lives on the heap through a short-lived short handle. Here is the output from doing a gcroot on one of the Person objects: 0:022> !gcroot -nostacks 00000000048f8730 DOMAIN(00000000004BB4A0):HANDLE(WeakSh):3e1528:Root:0000000002b25ab8(MS.Win32.HwndWrapperHook)-> 0000000002b25990(MS.Win32.HwndWrapper)-> 0000000002b249f0(System.Windows.Threading.Dispatcher)-> 0000000002b49c50(System.Windows.Input.InputManager)-> 0000000002b4a7a8(System.Windows.Input.StylusLogic)-> 0000000002b4a9a0(System.Collections.Generic.Dictionary2[[System.Object, mscorlib],[System.Windows.Input.PenContexts, PresentationCore]])-> 0000000002b4aa20(System.Collections.Generic.Dictionary
2+Entry[[System.Object, mscorlib],[System.Windows.Input.PenContexts, PresentationCore]][])-> 0000000002d6c848(System.Windows.Interop.HwndSource)-> 0000000002bed178(DataGridCTPSample.DataGridBasicSample_Demo2)-> 0000000002bf9300(Microsoft.Windows.Controls.DataGrid)-> 00000000048be620(DataGridCTPSample.People)-> 00000000048be790(System.Collections.Generic.List`1[[DataGridCTPSample.Person, DataGridCTPSample]])-> 00000000048e15c0(System.Object[])-> 00000000048f8730(DataGridCTPSample.Person) Since the reference isn't a strong handle or isn't pinned I tried to see if it just wasn't getting collected early enough and that is the reason. Try adding the GC.Collects to the code above and you'll find the heap does not explode. void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { //throw new NotImplementedException(); DataGrid_Standard.Dispatcher.Invoke((Action)delegate() { DataGrid_Standard.ItemsSource = new People(20); }); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); }Anonymous
September 03, 2009
The comment has been removedAnonymous
September 09, 2009
Trey, Please take a look at this thread, http://wpf.codeplex.com/Thread/View.aspx?ThreadId=63315.Anonymous
January 10, 2010
hi, this is very useful for me. Thanks for sharing ur ideas.I have a problem with adding DatagridTemplate column with Image dynamically i coded like this but its not working.can u suggest any better approach : FrameworkElementFactory factory = new FrameworkElementFactory(typeof(Image)); Binding b = new Binding("Image"); factory.SetValue(Image.SourceProperty, b); DataTemplate cellEditingTemplate = new DataTemplate(); cellEditingTemplate.VisualTree = factory; DataGridTemplateColumn imageColumn = new DataGridTemplateColumn(); imageColumn.Header = "Image"; imageColumn.CellEditingTemplate = cellEditingTemplate; dgDynamicColumns.Columns.Add(imageColumn); If at all i tried this for DataPicker its working fine but for Image it is failing to display a Image in the Column. How to Show Image column in the Datagrid from code. Thanks in Advance, Saru