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

GridView Binding to another column

4 Answers 240 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Neil
Top achievements
Rank 1
Neil asked on 26 Jan 2010, 02:28 PM
Hi,

I'm trying to use the DataGridView control with a DataTemplate.    This bit seems ok at the moment.

I am planning on using a convertor to automatically select the CellStyle based on the value of the column.  I expect this shouldn't be too tricky.

What I am having problems with is trying to bind the content of the control to another cell's value.  Or using another cells value for a property. 

Any help/examples would be greatly appreciated.

Eg

Record
======

Name = "My Textbox"
Control = "Textbox"
Default = "This is my default value"

The Control Column will become a TextBox and I would like the TextBox Value to become the value of the Default,

I have tried things like

Text="{Binding Default}"
Text="{Binding Path=Default, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewRow}}}"

<UserControl x:Class="WizardAdvanced" 
    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">  
    <Grid> 
        <Grid.Resources> 
            <Style x:Key="CheckboxCellStyle" TargetType="{x:Type telerik:GridViewCell}">  
                <Setter Property="ContentTemplate">  
                    <Setter.Value> 
                        <DataTemplate> 
                            <CheckBox VerticalAlignment="Center" /> 
                        </DataTemplate> 
                    </Setter.Value> 
                </Setter> 
            </Style> 
            <Style x:Key="TextboxCellStyle" TargetType="{x:Type telerik:GridViewCell}">  
                <Setter Property="ContentTemplate">  
                    <Setter.Value> 
                        <DataTemplate> 
                            <TextBox Text="{Binding Default}" /> 
                        </DataTemplate> 
                    </Setter.Value> 
                </Setter> 
            </Style> 
            <Style x:Key="ListboxCellStyle" TargetType="{x:Type telerik:GridViewCell}">  
                <Setter Property="ContentTemplate">  
                    <Setter.Value> 
                        <DataTemplate> 
                            <ComboBox  HorizontalAlignment="Left" VerticalAlignment="Bottom"/>  
                        </DataTemplate> 
                    </Setter.Value> 
                </Setter> 
            </Style> 
        </Grid.Resources> 
          
        <telerik:RadGridView Margin="0" Name="Grid" AutoGenerateColumns="False">  
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"></telerik:GridViewDataColumn> 
                <telerik:GridViewDataColumn Header="Control" DataMemberBinding="{Binding Control}" CellStyle="{StaticResource TextboxCellStyle}"></telerik:GridViewDataColumn> 
                <telerik:GridViewDataColumn Header="Default" DataMemberBinding="{Binding Default}"></telerik:GridViewDataColumn> 
 
            </telerik:RadGridView.Columns> 
        </telerik:RadGridView> 
 
    </Grid> 
</UserControl> 
 

4 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 26 Jan 2010, 04:27 PM
Hello Neil,

I believe using Text={Binding Default } should work just fine.

Please see it in action in the attached sample.

Best wishes,
Pavel Pavlov
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
Neil
Top achievements
Rank 1
answered on 26 Jan 2010, 04:54 PM
Hi

Thanks for your quick reply.

I'm using a XML File.  Would that make any difference?  I am loading the data into a DataSet and then binding it to the Grid.  Basically the same as you have done in code but with an XML file.

<Items>

<

 

Item>

 

<

 

Name>Template Title</Name>

 

<

 

Control>textbox_string</Control>

 

<

 

ParamName>TITLE</ParamName>

 

<

 

Default>Queue Display</Default>

 

</

 

Item>
</Items>

This basically gives me blank boxes.  

Any ideas would be appreicated.

Kind regards
Neil

 

0
Neil
Top achievements
Rank 1
answered on 27 Jan 2010, 08:27 AM
Hi,

I have solved the problem.  I tested with the List Collection and it worked in my code.   It then occurred to me that the XML Tag Default is a reserved word.   

I then changed the code in XAML to the following and it worked:

<TextBox Text="{Binding Path=[Default]}" /> 

Puttin square brackets around it solved the issue.   Strange that it worked in a List collection and not in XML though.

Thanks for your help.  It got me to a solution :)

0
Pavel Pavlov
Telerik team
answered on 27 Jan 2010, 05:46 PM
Hi Neil,
Thanks for sharing the solution! Such things are always good to have in mind.
If further need of assistance occurs - don't hesitate to contact us.

All the best,
Pavel Pavlov
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.
Tags
GridView
Asked by
Neil
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Neil
Top achievements
Rank 1
Share this question
or