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

[Solved] Set DataFormatString maximum length

1 Answer 160 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard Harrigan
Top achievements
Rank 1
Richard Harrigan asked on 18 Dec 2010, 07:42 PM
Hi,

gridViewDataColumn.DataFormatString. = "{0:(###) ###-####}";

Int64.Parse("6909186699");    Displays as (690) 918-6699

Int64.Parse("69091866990");    Displays as (6909) 186-6990

How can I prevent the user from entering the 11th digit?  Do I need to handle it in the RadGridView1.CellValidating event?

Thanks
Rich

1 Answer, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 20 Dec 2010, 11:44 AM
Hello Richard,

 
The DataFormatString property formats the data you displayed either in a GridViewDataColumn or GridViewComboBoxColumn. To achieve the desired result you need to validate the data on different levels. There are couple of approaches you may use, below is a sample that uses RadGridView's CellValidating event:

MainPage.xaml:

<telerik:RadGridView Margin="114,77,109,91" CellValidating="RadGridView_CellValidating" AutoGenerateColumns="False" ItemsSource="{Binding Collection}">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataFormatString="{}{0:(###) ###-####}" UniqueName="ID" Header="P1" DataMemberBinding="{Binding Property1}"/>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

MainPage.xaml.cs:

private void RadGridView_CellValidating (object sender, Telerik.Windows.Controls.GridViewCellValidatingEventArgs e)
        {
            if (e.Cell.Column.UniqueName == "ID")
            {
               
                if (e.NewValue.ToString().Length > 10)
                {
                    e.IsValid = false;
                    e.ErrorMessage = "The entered value must be 10 characters long";
                }
            }
        }

Alternatively, you can use our MaskedTextBox column.

Kind regards,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Richard Harrigan
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question
or