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

GridViewCell.Field + Unique name nested objects

3 Answers 187 Views
GridView
This is a migrated thread and some comments may be shown as answers.
NS
Top achievements
Rank 1
NS asked on 17 Nov 2008, 08:23 AM
Hi,

I've update to the last version but now i have 2 problems with it
  1. When i get the gridviewcell from a dependancy object and then try to get the field property (what existed in the previous versions), it doesn't exist anymore ? (the code comes from a datacombo selection changed in the grid)
     DependencyObject item = e.OriginalSource as DependencyObject;  
     while (!(item is GridViewCell))  
     {  
         item = VisualTreeHelper.GetParent(item);  
     }  
     
     
     
     if ((sender as ComboBox).SelectedItem != null)  
     {  
        PrinterTray p = (sender as ComboBox).SelectedItem as PrinterTray;  
                            QueueItem q = ((item as GridViewCell).Field.Record as DataRecord).Data as QueueItem;  
                            q.SetPrinterTrayKeys(p.ReportServiceId, p.PrinterId, p.PrinterTrayId);  
     } 
  2. When i add a column that is set to a nested object then it doesn't work anymore (worked fine in the previous versions) but now it doens't display anything. (QueueItem.Status.StatusId)
    <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="StatusId" UniqueName="QueueItem.Status.StatusId" /> 

 

3 Answers, 1 is accepted

Sort by
0
Hristo Deshev
Telerik team
answered on 18 Nov 2008, 04:45 PM
Hi NS,

I am sorry for delay in our answers. Straight to your questions:
  1. We got rid of the Field class so that we do not have to insert temporary objects holding values between the data source items and the cells. We are getting several benefits like performance improvements and property change notifications with that change, at the cost of breaking backwards compatibility. Looking at your code, it really needs to get the data item (the QueueItem) instance from the GridViewCell control. You can do that by getting the cell data context:

    (item as GridViewCell).DataContext as QueueItem
  2. We rectified something, I consider a bug in the previous implementation -- we were making customers use the column UniqueName property as a property path storage. We finally turned that into a unique column identifier that would allow you to just find your column in the RadGridView.Columns collection. To set the property path, you need to now set the DataMemberPath property. I think that this XAML should do the trick:

    <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="StatusId" UniqueName="QueueItem.Status.StatusId" DataMemberPath="QueueItem.Status.StatusId" />
Tell me if the above suggestions fix your problem.
Greetings,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
NS
Top achievements
Rank 1
answered on 19 Nov 2008, 04:07 PM
No,

the datamemberpath on the column doesn't work, but the data is there for the status because i use a converter to change the forecolor of the rows based on there status.

Here is some the xaml for my grid and converter

        <Converter:DocumentColorConverter  x:Key="ConvertDocumentColor" /> 
         
        <Style TargetType="{x:Type telerik:GridViewRow}">  
            <Setter Property="Foreground" Value="{Binding Path=Data.QueueItem.Status.StatusId, Converter={StaticResource ConvertDocumentColor}}" /> 
        </Style> 

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
        {  
              
            System.Windows.Media.Brush returnValue;  
            string controlType = "";  
            if (value != null)  
                controlType = value.ToString();  
 
            switch (controlType)  
            {  
                case "E":  
                    returnValue = Brushes.Red;  
                    break;  
                case "D":  
                    returnValue = Brushes.Black;  
                    break;  
                default:  
                    returnValue = Brushes.Blue;  
                    break;  
                  
            }  
 
            return returnValue;  
        } 


<telerik:RadGridView ScrollMode="RealTime" IsFilteringAllowed="False" AutoGenerateColumns="False"  x:Name="radGridDocuments" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" Grid.Column="1" telerik:Theming.Theme="Caramel" FontSize="11" FontFamily="Tahoma" OverridesDefaultStyle="False" IsReadOnly="True" Grid.RowSpan="2" Grid.Row="1" MultipleSelect="True" Background="{x:Null}" TabIndex="6">  
              
            <telerik:RadGridView.ContextMenu> 
                <ContextMenu> 
                    <MenuItem Header="Documents for this truck" x:Name="ctxDocTruck" Click="ctxDocTruck_Click" IsCheckable="True" /> 
                    <MenuItem Header="Resubmit" x:Name="ctxResubmit" Click="ctxResubmit_Click" /> 
                    <MenuItem Header="Load from archive" x:Name="ctxArchive" Click="ctxArchive_Click" /> 
                </ContextMenu> 
            </telerik:RadGridView.ContextMenu> 
            <telerik:RadGridView.RowAppearance> 
                <telerik:RowAppearanceSettings UseAlternateRowStyle="False"/>  
            </telerik:RadGridView.RowAppearance> 
           <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Document n°" UniqueName="DocumentNumber" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Log" UniqueName="LogId"  /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Layout" UniqueName="LayoutCode" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Job" UniqueName="JobId" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Pallet Id" UniqueName="PalletId" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Shipment Id" UniqueName="ShipmentId" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="User" UniqueName="UserName" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="ShippingPointId" UniqueName="ShippingPointId" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Customer" UniqueName="CustomerName" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Groupage" UniqueName="Groupage" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="CDC" UniqueName="CDC" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Entity" UniqueName="Entity"  /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Article" UniqueName="Article" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Creation" UniqueName="CreationTime" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Status" UniqueName="QueueItem.Status.Description" DataMemberPath="QueueItem.Status.Description" /> 
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="StatusId" UniqueName="QueueItem.Status.StatusId" DataMemberPath="QueueItem.Status.StatusId" /> 
                  
                <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="ImportId" UniqueName="ImportId" /> 
               <telerik:GridViewDataColumn Width="Auto" DataType="{x:Null}" HeaderText="Sender" UniqueName="Sender" /> 
            </telerik:RadGridView.Columns> 
        </telerik:RadGridView> 

I also noticed in the previous version when the column was a nested one, you can't order on it.

Regards
0
Accepted
Pavel Pavlov
Telerik team
answered on 21 Nov 2008, 04:43 PM
Hi NS,

To see the DataMemberPath working, please set the DataType property of the column correctly. I believe in your case it is a string. So please replace

DataType

 

="{x:Null}"

 

 

with

DataType

 

="{x:Type sys:String}"

 

 

for the problematic column.

Regards,
Pavel Pavlov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
NS
Top achievements
Rank 1
Answers by
Hristo Deshev
Telerik team
NS
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or