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

GridViewDataColumn - Issue generating GridViewDataColumn dynamically.

4 Answers 87 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nikhil Thaker
Top achievements
Rank 1
Nikhil Thaker asked on 28 Jul 2010, 10:41 AM
Hi,

I am generating GridViewDataColumns dynamically using following code. 

 

var isUnReadColumn = new GridViewDataColumn
  
{
  
    Header = isUnreadImage,
  
    Width = new GridViewLength(22, GridViewLengthUnitType.Auto, 22, 22),
  
    DataMemberBinding = new Binding(EmailMessageController.COLUMNISUNREAD)
  
    {
  
        Converter = new EmailBoolToReadUnreadImageConverter()
  
    }
  
};

This code was working fine untill I started using new Telerik Dlls released on 14th July, 2010.
The converter here in the code is just converting boolean value to image(Open mail image for read emails and close mail image for unread email). Now after using new Dlls this code is neither generating any image through converter nor raise any exception.

Same thing is happening to all the converters in the system and none of them is working as before.

So what can be the solution to this issue..?

Thanks in advance.

 

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 28 Jul 2010, 03:11 PM
Hi Nikhil Thaker,

 
I have tried to reproduce your problem, but everything works as expected and the the converters are properly applied.
I am sending you a sample project that you can use as a reference. In case there is some kind of misunderstanding considering your requirements, please provide us with more details about your application.

Sincerely yours,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Maya
Telerik team
answered on 28 Jul 2010, 03:15 PM
Hello Nikhil Thaker,

I have missed to attached the sample project in the previous post, so please find it attached to this one.

All the best,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nikhil Thaker
Top achievements
Rank 1
answered on 29 Jul 2010, 08:58 AM
Hi,

Thanks for the quick reply.

First of all you have implemented the Converter in xaml code where in my case I am doing it in c# code (check the code block in my last post) as I am generating all the columns programmatically.

Apart of this let me clear some other points.

1.> Generating all the columns of the GridView programmatically and not in xaml.
2.> Implementation of converter  and use of converter is in two separate silverlight projects.
3.> Bringing images from a server project in my solution.
4.> Following is the Convert method that I am using.
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && (bool)value)
            {
                var attachmentImage = new Image()
                                          {
                                              Height = 12,
                                              Width = 12,
                                              HorizontalAlignment = HorizontalAlignment.Center
                                          };
                attachmentImage.Source = new BitmapImage(new Uri(ImageDB.Email.WITHATTACHMENT, UriKind.RelativeOrAbsolute));
  
                return attachmentImage;
            }
            else
            {
                return null;
            }
        }


Hope this helps you understanding the scenario.

Thanks again.
0
Accepted
Maya
Telerik team
answered on 30 Jul 2010, 10:17 AM
Hi Nikhil Thaker,

Indeed, following the way you are developing your converter, it turns out that is not quite applicable according to the internal logic implemented in our GridViewDataColumn in our latest versions.
However, there are a couple of possible solutions in this case. Firstly, you may define a CellTemplate for your GridViewDataColumn. For example:

<UserControl.Resources>
       <my:BooleanToImageConverter x:Key="BoolToImageConverter" />
       <DataTemplate x:Key="CellTemplate">
           <StackPanel>
               <Image Source="{Binding Path=IsKoala, Converter={StaticResource BoolToImageConverter}}" Width="50" Height="50" />
           </StackPanel>
       </DataTemplate>
   </UserControl.Resources>

GridViewDataColumn nationalityColumn = new GridViewDataColumn();
nationalityColumn.DataMemberBinding = new Binding("NationalityFlag");
nationalityColumn.IsReadOnly = true;
nationalityColumn.CellTemplate = (DataTemplate) Resources["CellTemplate"];
 
this.playersGrid.Columns.Add(nationalityColumn);
  
The other possibility is to define a GridViewImageColumn:
GridViewImageColumn nationalityColumn = new GridViewImageColumn();
nationalityColumn.DataMemberBinding = new Binding("IsKoala")
{
    Converter = new BooleanToImageConverter()
};
nationalityColumn.IsReadOnly = true;
 
this.playersGrid.Columns.Add(nationalityColumn);

However, in both cases the value returned by your converter should be the Source of the image, not the image itself:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            {
                if (value != null && (bool)value)
                {
                    var attachmentImage = new Image()
                    {
                        Height = 12,
                        Width = 12,
                        HorizontalAlignment = HorizontalAlignment.Center
                    };
                    attachmentImage.Source = new BitmapImage(new Uri(ImageDB.Email.WITHATTACHMENT, UriKind.RelativeOrAbsolute));
 
                    return attachmentImage.Source;
                }
                else
                {
                    return null;
                }
            }
                         
        }
 

I hope that helps. Please excuse us for the inconvenience caused.

All the best,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Nikhil Thaker
Top achievements
Rank 1
Answers by
Maya
Telerik team
Nikhil Thaker
Top achievements
Rank 1
Share this question
or