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

Textbox Cell Style

13 Answers 589 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rick Knicely
Top achievements
Rank 1
Rick Knicely asked on 08 Oct 2010, 03:13 AM
Hello,
I am trying to set the style of my GridViewDataColumn to a textbox and am having some difficulty.
This is the latest thing I have tried.  It seems that i should not be having this much trouble.
I have seen examples of checkboxes and images but cannot find a RadMaskedTextBox example. Could you provide one?

Thank you.
                        <telerikPres:RadGridView ItemsSource="{Binding}>
                            </telerikPres:RadGridView.Columns>
                                    <telerikPres:GridViewDataColumn Header="My RadMaskedTextBox" UniqueName="MyDecimalField">
                                        <telerikPres:GridViewColumn.CellStyle>
                                            <Style TargetType="{x:Type telerikPres:GridViewCell}">
                                                <Setter Property="Template">
                                                    <Setter.Value>
                                                        <ControlTemplate TargetType="{x:Type telerikPres:GridViewCell}">
                                                            <telerikInput:RadMaskedTextBox Margin="0 3 0 3"  Width="55" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=MyDecimalField, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center"  MaskType="Numeric" Mask="n2"  />
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                            </telerikPres:GridViewColumn.CellStyle>
                                    </telerikPres:GridViewDataColumn>
                            </telerikPres:RadGridView.Columns>

13 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 08 Oct 2010, 07:32 AM
Hello,

 Why not use CellTemlate directly to place desired control?

All the best,
Vlad
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
Rick Knicely
Top achievements
Rank 1
answered on 08 Oct 2010, 12:10 PM
Maybe I am going about it the wrong way.

Do you have an example in the documentation I can look at?
0
Vlad
Telerik team
answered on 08 Oct 2010, 12:13 PM
Hi,

 You can check this demo for more info about how to define CellTemplate/CellEditTemplate. 

Best wishes,
Vlad
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
Rick Knicely
Top achievements
Rank 1
answered on 08 Oct 2010, 12:20 PM
Thank you :)

I am going to go take a look.

However, I would still like to know why the two way binding will not work with the code I've been trying.
0
Vlad
Telerik team
answered on 08 Oct 2010, 12:27 PM
Hello,

Have you tried?

Value="{Binding MyDecimalField, Mode=TwoWay}"

Regards,
Vlad
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
Rick Knicely
Top achievements
Rank 1
answered on 08 Oct 2010, 12:52 PM
Yes and I just tried the cellTemplate. In both cases the value displays correctly in the cell, however it does not bind back to the GridViewDataColumn nor the bound ObservableCollection.  And with the TemplatedBinding nothing is bound. I even added a simple converter to check the value.  The only way I get any data is if I use the method you mentioned -- Value="{Binding MyDecimalField, Mode=TwoWay}".  But is is not binding back to the gridItem nor Collection.

BTW - thank you for the quick response.

                                <telerik:GridViewDataColumn Header="Man Years Required" DataMemberBinding="{Binding ManYearsRequired, Mode=TwoWay}">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding ManYearsRequired}" />
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                    <telerik:GridViewDataColumn.CellEditTemplate>
                                        <DataTemplate>
                                                <telerik:RadMaskedTextBox Margin="0 3 0 3"  Width="55" Value="{Binding ManYearsRequired, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center"  MaskType="Numeric" Mask="n2" Tag="MOA" />
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellEditTemplate>
                                </telerik:GridViewDataColumn>
0
Rick Knicely
Top achievements
Rank 1
answered on 08 Oct 2010, 01:19 PM
It appears to be when trying to use the RadMaskedTextBox for the DataTemplate.  If I use a regular TextBox the binding works as expected.  Do I have to do anything special to the GridViewDataColumn in the RadGridView to type it as a Decimal if using the RadMaskedTextBox?

Can you provied an example of using the RadMaskedTextBox as the DataTemplate for a CellTemplate and/or CellStyle?

Thank you,
Rick

This XAML works...

                                <telerik:GridViewDataColumn Header="Man Years Required" DataMemberBinding="{Binding ManYearsRequired, Mode=TwoWay}">
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                                <TextBox Margin="0 3 0 3"  Width="55" Text="{Binding ManYearsRequired, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center"/> <!-- MaskType="Numeric" Mask="n2" Tag="MOA" />-->
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                    <telerik:GridViewDataColumn.CellEditTemplate>
                                        <DataTemplate>
                                                <TextBox Margin="0 3 0 3"  Width="55" Text="{Binding ManYearsRequired, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center"/> <!--  MaskType="Numeric" Mask="n2" Tag="MOA" />-->
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellEditTemplate>
                                </telerik:GridViewDataColumn>
0
Rick Knicely
Top achievements
Rank 1
answered on 08 Oct 2010, 01:32 PM
It does seem to be the RadMaskedTextBox. The original CellStyle code works correctly with a TextBox too. 

                                <telerik:GridViewDataColumn Header="Man Years Required" DataMemberBinding="{Binding ManYearsRequired, Mode=TwoWay}">
                                <telerik:GridViewColumn.CellStyle>
                                    <Style TargetType="{x:Type telerik:GridViewCell}">
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type telerik:GridViewCell}">
                                                    <TextBox Margin="0 3 0 3"  Width="55" Text="{Binding ManYearsRequired, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" /> <!--</TextBox>MaskType="Numeric" Mask="n2" Tag="MOA" />-->
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                    </telerik:GridViewColumn.CellStyle>                                       
                                  </telerik:GridViewDataColumn>
0
Rick Knicely
Top achievements
Rank 1
answered on 08 Oct 2010, 02:11 PM
Okay... I put both the RadMaskedTextBox and the TextBox in a template.  The TextBox works and the RadMaskedTextBox does not.
Does the RadMaskedTextBox need the GridViewDataColumn to be typed?

                            <ControlTemplate x:Key="cellTextTemplate" TargetType="{x:Type telerik:GridViewCell}">
                                <StackPanel>
                                        <telerik:RadMaskedTextBox Margin="0 3 0 3"  Width="55" Value="{Binding ManYearsRequired,  Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" MaskType="Numeric" Mask="n2" Tag="MOA" />
                                        <TextBox Margin="0 3 0 3"  Width="55" Text="{Binding ManYearsRequired,  Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center"/> <!-- MaskType="Numeric" Mask="n2" Tag="MOA" />-->
                                </StackPanel>
                            </ControlTemplate>
                            <Style x:Key="textCellStyle">
                                <Setter Property="telerik:GridViewCell.Template" Value="{StaticResource cellTextTemplate}" />
                            </Style>
0
Rick Knicely
Top achievements
Rank 1
answered on 08 Oct 2010, 02:37 PM
I tried the GridViewMaskedTextBoxColum, just found it...  It seems that it is the numeric mask that is failing, standard mask works.

works
                                    <telerik:GridViewMaskedTextBoxColumn DataMemberBinding="{Binding ManYearsRequired, Mode=TwoWay}"
                                    Header="Test"
                                    UniqueName="ManYearsRequired2"
                                    MaskType="Standard" Mask="####"/>

does not work
                                    <telerik:GridViewMaskedTextBoxColumn DataMemberBinding="{Binding ManYearsRequired, Mode=TwoWay}"
                                    Header="Test"
                                    UniqueName="ManYearsRequired2"
                                    MaskType="Numeric" Mask="n2"/>

Ideas?  This is even with just the GridViewMaskedTextBoxColumn, not even a tempate...
0
Rick Knicely
Top achievements
Rank 1
answered on 08 Oct 2010, 03:13 PM
Tried typing the column...
Still no luck... 
Any idea how to make the MaskedTextBox work with a numeric mask to decimal data in the RadGridView?  I really do not want to use the standard mask.  If I have to use standard mask #.# only formats my data, not correctly.  90 is formated as 9.0.  How would i do a standard mask for 9.99?  one digit, decimal point, to digits after decimal point.

                                    <telerik:GridViewMaskedTextBoxColumn DataType="{x:Type system:Decimal}" DataMemberBinding="{Binding ManYearsRequired, Mode=TwoWay}"
                                    Header="Test"
                                    UniqueName="ManYearsRequired2"
                                    MaskType="Numeric" Mask="n2"/>
0
Alena
Top achievements
Rank 1
answered on 12 Oct 2010, 09:25 AM
I have similar problem with GridViewMaskedTextBoxColumn. When I use numeric mask ("n2") number 23,65 is formated as 23.65. When I use standard mask ("00,00") number 23,65 is formated as 2365. How can I get double number 23,65?
0
Veselin Vasilev
Telerik team
answered on 13 Oct 2010, 04:11 PM
Hi Rick,

Have you tried changing the underlying property from decimal to double? That should work.

Best wishes,
Veselin Vasilev
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
Rick Knicely
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Rick Knicely
Top achievements
Rank 1
Alena
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or