This is a migrated thread and some comments may be shown as answers.

Update binding of a GridViewImageColumn

9 Answers 245 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 19 Aug 2011, 02:28 PM
Hi,

I've some problem to manage one binding.

Here is my case:

I've a RadGridView, which basically allows me to sort/search/filter a datacollection, and then details are displayed and editable on the right of the radGridview.

One column is a GridViewImageColumn. This image represent the "status" of the element of the current row.

Here is my binding: 
DataMemberBinding="{Binding Converter={StaticResource MyRowToImageConverter}}"


To display the content of this column, I need a converter, which takes the whole current row, analyze it and give the correct image.

This choice is made on several fields(Enums, ObservableCollections, ...)

The converter is working good and display the correct icon, the problem, is that when something change(the most typical case is the ObservableCollection, which get a new element), the binding isn't aware of this change.

So I don't see how to update this fields:
-I don't think it's possible to have a Multiple data binding in the radGridView(if yes, I can bind every fields I use for the calculation, and then, when one change, I receive the change event and then the binding is automatically updated)
-In the code behind I get informed when I should update thoses fields, but I've no idea about how to ask to refresh one(or all) binding of the current row

So how can I do this??

Thank you for your help


9 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 22 Aug 2011, 03:27 PM
Hi Julien,

I have prepared a very simple project that illustrates a possible approach to this scenario, utilizing INotifyPropertyChanged. I am attaching it for your reference.

Regards,
Ivan Ivanov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Julien
Top achievements
Rank 1
answered on 23 Aug 2011, 06:07 AM
Hi,

There is an huge difference between your example and mine, I cannot bind a property of the current object, but the full object, because the converter is using several fields of my object.

All my objects have already the INotifyPropertyChanged. And all other column are already automatically updated,
0
Pavel Pavlov
Telerik team
answered on 23 Aug 2011, 12:23 PM
Hello Julien,

RadGridView has two ways of refreshing the UI after changes in data.
1. INotifyPropertyChanged
2. Calling the Rebind() method.

Since INotifyPropertyChanged is usable only when you bind to a property ( not the  entire object) , we remain only with the second option - call the Rebind method of RadGridView after a change in the data was made.

Regards,
Pavel Pavlov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Julien
Top achievements
Rank 1
answered on 23 Aug 2011, 12:42 PM
Okay, but this method rebind what? The current row? the whole table? visible row? ...?
0
Pavel Pavlov
Telerik team
answered on 23 Aug 2011, 01:07 PM
Hi Julien,

The whole table.

All the best,
Pavel Pavlov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
oarrivi
Top achievements
Rank 1
answered on 25 Jun 2012, 02:17 PM
Hello Pavel

What about filter values?. I mean, your example is perfect for my because I'm trying to change the ugly text displayed in the filter control.
I want to show "decreasing", "increasing" or "unchanged" instead of "images\increasing.png".

How can I change these values displayed in the filter control?

Thank you very much


Oscar
0
Pavel Pavlov
Telerik team
answered on 25 Jun 2012, 03:38 PM
Hi Oscar ,

For the very next service pack - planned for 24 th of July RadGridView will have some improvements in this context - filtering control for image columns will show the images , rather than their text representation.

Would that work for you?

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
oarrivi
Top achievements
Rank 1
answered on 26 Jun 2012, 07:52 AM
Hi Pavel

That's perfect and more logical behavior then before. Thank you very much.

I guess that if I want to show texts rather than their images, I would have to build a custom filter control. Right?
Anyway the new features will go to me much better than now.

Best regards,

Oscar
0
Pavel Pavlov
Telerik team
answered on 29 Jun 2012, 11:46 AM
Hi Julien,

I have some updates on the issue. I have talked to the guys responsible for filtering. It appears there is some uncertainty about the feature. They are not sure whether it is going to be included in the service pack as they are experiencing some design and appearance problems with differently sized images and similar marginal cases.

Therefore I think I owe you an alternative solution :

public class ImageFilterColumn : GridViewImageColumn
    {
        /// <summary>
        /// Gets the filtering display function.
        /// </summary>
        /// <value>The filtering display function.</value>
        /// <remarks>This function is used by the filtering control distinct values list.
        /// It accepts a raw data value and returns what will become the content of the
        /// distinct value checkbox.</remarks>
        protected override Func<object, object> FilteringDisplayFunc
        {
            get { return ImageFilterColumn.ConvertUriStringToImage; }
        }
 
        public static object ConvertUriStringToImage(object uriString)
        {
            var image = new Image();
            image.Source = new BitmapImage(new Uri(uriString.ToString(), UriKind.Relative));
            return image;
        }
    }


Use the ImageFilterColumn from above , instead of the Regular image column. Actually you can modify the Func above to return your own modified text, image or whatever you need.
e.g.
protected override Func<object, object> FilteringDisplayFunc
 
        {
 
            get { return  "My custom text"; }
 
        }


Let me know in case you need the above code integrated in a working example .

Regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Julien
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Julien
Top achievements
Rank 1
Pavel Pavlov
Telerik team
oarrivi
Top achievements
Rank 1
Share this question
or