We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DataTemplate persistence

Thread ID:





75930 Aug 15,2008 01:27 PM UTC Aug 22,2008 12:56 AM UTC WPF 10
Tags: GridControl
Administrator [Syncfusion]
Asked On August 15, 2008 01:27 PM UTC

The datatemplate that I place in individual cells is not persisting the data from user input.

To replicate this problem:

(1) Use a tabbed interface with two or more tabs

(2) Place a wpf grid on one of the tabs

(3) On the grid, add a datatemplate (here is my code):
Model[2, 2].CellType = "DataTemplate";
Model[2, 2].CellTemplateKey = "dtLeftJustify";

Here is my data template as a an example:

(4) When you run the application, add data to cell 2,2 in addition to other cells.

(5) click on the non-grid tab

(6) click back on the grid tab. Data in cell 2,2 will be gone, but any other data that a user typed is still there.

Thanks in advance for your help.

Administrator [Syncfusion]
Replied On August 15, 2008 03:05 PM UTC

Here is a little sample showing this working using our latest code from 6.3.1.x that should be available for download from our website Monday or Tuesday of next week.


In your case, is GridText a public property on some object that you are setting as the grid's cellvalue for that cell? (This stores it into the GridStyleInfo object for the cell.)

Everything about the cell that needs to be persisted should be stored in the GridStyleInfo object for that cell. The DataTemplate objects themselves are virtualized, meaning they will go out of scope as the particular cell goes out of the view either from scrolling or as in this case from changing tabs. So, the underlying cell data must be persisted through the GridStyleInfo object for the cell. These GridStyleInfo objects will not go out of scope.

Administrator [Syncfusion]
Replied On August 15, 2008 08:21 PM UTC

Thanks Clay. That worked.

Administrator [Syncfusion]
Replied On August 20, 2008 08:51 PM UTC


I appreciate your help. I am stuck on trying to pull data in and out of a datatemplate. So, I created a simple project.

It has:
A datagrid with a combobox
A Button
A textblock

I have two goals with this:
(1) I would like to find out how to make the button (outside of the grid) change data within the combobox.
(2) I would also like to find out how to make a change in the combobox change the text in a textblock outside of the grid.

I have placed this in the forum because I think it might help other people trying to use a datatemplate which are extremely important to the syncfusion grid.

Attached please find my sample. Any help would be greatly appreciated.


Administrator [Syncfusion]
Replied On August 20, 2008 11:08 PM UTC

In your DataTemplate, there was no binding information set up. So, this was added to bind the SelectedIndex to the GridValue:

Once this is done, you can get the combobox outside the grid to set the value inside the grid to Dallas using code like:

private void btnChangeComboBox_Click(object sender, RoutedEventArgs e)
//Add Code
GridValueContent cellValue = myGrid1.Model[2, 2].CellValue as GridValueContent;
cellValue.GridValue = 1;

Now getting the TextBlock to change as you change the DataTemplate cell in the grid is a little more involved. You have to catch some kind of change event to be able to do this. The grid itself will not raise such an event because the controls are in the DataTemplate and not really part of the grid itself. So you could either create a custom DataTemplate CellType and expose an change event on the combobox in the template, or you could expose a change event on the data object. Here is the sample modified with the data object implementing INotifyPropertyChanged to allow you to catch the changes so you can put them in the TextBlock.


Administrator [Syncfusion]
Replied On August 21, 2008 08:24 PM UTC

Thanks. This has really helped.

I noticed one last detail that I am not able to work out: The selectedindex of the combobox does not change when I click the downarrow of the combobox. Your code seems like it handled this. For some reason, though, it doesn't work.

To reproduce my problem, open the sample you created. Then try to click on the down arrow of the combobox to say "Boston". The textbox of the combobox will not show "Boston" after you do that.

Many thx.

Administrator [Syncfusion]
Replied On August 21, 2008 09:01 PM UTC

I am not following what you are describing.

Clicking the dropdown button only drops the combobox. It will not change the selection. In this templated combobox, if you want the mouse down to move the selected index, you could override the combobox's OnPreviewMouseDown and catch the lcik there and move the selected index yourself if the combobox is already dropped.

Administrator [Syncfusion]
Replied On August 21, 2008 09:58 PM UTC

Here is an override in CustomComboBox that moves the selectedindex on each click of the button fro me in that sample.

protected override void OnPreviewMouseDown(System.Windows.Input.MouseButtonEventArgs e)
if (this.IsDropDownOpen)
int i = SelectedIndex + 1;
if (i >= this.Items.Count)
i = 0;
SelectedIndex = i;
e.Handled = true;

Administrator [Syncfusion]
Replied On August 22, 2008 12:21 AM UTC

Thanks. I did try your additional code and it worked as you mentioned.

My problem is more basic than that though. When I click on the down arrow of the combobox, I want it to function like a normal combobox. In this case, when I click on the down arrow of the combobox and select "Boston", it closes the drop down. However, "Boston" does not become the selecteditem. It still shows "".

Administrator [Syncfusion]
Replied On August 22, 2008 12:39 AM UTC

I do not see this behavior. When I click Boston, the combobox closes and shows Boston. Now, I am using the latest code base, 6.3.1.x. This version will be up on our web site for download any day now.

Administrator [Syncfusion]
Replied On August 22, 2008 12:56 AM UTC

ah ok. That explains it. I'm using an older version of the grid than you. So, it seems that my latest problem will be solved when I update the grid with a newer version.

This was a good exercise for me. I will be able to take what you wrote and use it to manage my datatemplates in the grid. I think this thread is done.

Thanks again.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon