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

RadGridView Customizing Column Problem

3 Answers 26 Views
GridView
This is a migrated thread and some comments may be shown as answers.
parag patel
Top achievements
Rank 1
parag patel asked on 23 Nov 2009, 11:12 AM
Hello Telerik,

My requirement is very simple for your grid view but still I am not able to fulfill it. Here I am presenting my problem:

In grid control in one column I just want display image as per my field value in data table column. I am using converter class for that.

Here  i am putting my code:

Here is first xaml file for user control:

<UserControl x:Class="UC_A1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"    
    xmlns:s="clr-namespace:WpfDrugApp"
    Height="300">
    <UserControl.Resources>
        <Style x:Key="IFrameworkInputElementStyle1" x:Name="ImageCell" TargetType="{x:Type IFrameworkInputElement}" />
        <s:ImageConverter x:Key="sColorConverter"></s:ImageConverter>
        <DataTemplate x:Key="GridViewCell" >
            <!--<Image Source="{Binding InteractionType,Converter={StaticResource sColorConverter}}"></Image>-->
            <StackPanel Orientation="Horizontal"  >
                <Image Source="{Binding Path=InteractionType, Converter={StaticResource sColorConverter}, Mode=OneWay}"></Image>
                <TextBlock Text="{Binding Path=InteractionType}"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>
    <Grid>

        <telerik:RadGridView x:Name="radGridView" AutoGenerateColumns="False" >
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding InteractionType}" Header="InteractionType"  UniqueName="InteractionType" CellTemplate="{StaticResource GridViewCell}"  >
                    
                </telerik:GridViewDataColumn>

                <telerik:GridViewDataColumn  DataMemberBinding="{Binding Severity}" Header="Severity"  UniqueName="Severity" />
                <telerik:GridViewDataColumn   DataMemberBinding="{Binding Message}" Header="Message" UniqueName="Message" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</UserControl>
 
and the code for vb file:

Private Sub UC_A1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
    
        Dim dt As New DataTable
        dt.Columns.Add("InteractionType")
        dt.Columns.Add("Severity")
        dt.Columns.Add("Message")
        Dim objR As DataRow = dt.NewRow
        objR.Item(0) = "1.jpeg"
        objR.Item(1) = "2"
        objR.Item(2) = "Moderate Drug Interaction between furosemide 20 mg oral tablet and enalapril 2.5 mg oral tablet"
        dt.Rows.Add(objR)

        radGridView.ItemsSource = dt
    End Sub

and code for converter class:
Public NotInheritable Class ImageConverter
    Implements IValueConverter


    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Try
            'Return New BitmapImage(New Uri(DirectCast(value, String)))
            Return "/WpfDrugApp;component/1.jpeg"

            'Return New BitmapImage(New Uri("D:\Jignesh Parmar\Testing\Multum\WPFDrugApp\WpfDrugApp\WpfDrugApp\bin\Debug\1.jpeg"))
        Catch
            Return New BitmapImage()
        End Try

    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack

        Throw New NotImplementedException()
    End Function

End Class

So can you provide me solution for that.....

plz reply as soon as possible.

3 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 23 Nov 2009, 02:54 PM
Hello Parag Patel,

I have created a sample application that demonstrates a possible solution for your case.

Basically your GridView is bound to DataTable. This means that each row is bound to DataRow with values that can be accessed through dictionary rather than normal properties. So to acquire the values in the cell template you need to bind to the specific value inside this dictionary (using .[key name] syntax).

If you have any more questions do not hesitate to contact us.

Best wishes,
Tsvyatko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
parag patel
Top achievements
Rank 1
answered on 24 Nov 2009, 04:10 AM
TO,Tsvyatko- the Telerik team


Hi can you please attach your example demonstrating your view.
That will be a nice help from your side.

Hoping for early reply

and thanks for your post
0
parag patel
Top achievements
Rank 1
answered on 24 Nov 2009, 04:29 AM
To Telerik,

I am able to solve it.

So its ok now.

Thanks for your post.
Tags
GridView
Asked by
parag patel
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
parag patel
Top achievements
Rank 1
Share this question
or