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

Validation on child gridView/table

4 Answers 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marty
Top achievements
Rank 1
Marty asked on 23 Apr 2009, 07:43 PM
I followed the Validation example from the demos to add validation to my gridView that happens to have a child grid.  It is working fine on the master table, however, on the child gridView, it's not working, the event is not even firing.  I'm assuming I'll have to bind the validation event to the child gridview as well, but how do I go about doing so?

Thanks,
Marty

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 24 Apr 2009, 11:47 AM
Hi Marty,

In order to get a hold of the child grid you will need to set the HierarchyChildTemplate of the parent grid. Once you have access to the child grid, you can attach to the appropriate event (or do anything else with it as a matter of fact). Here is how to do this using XAML:

<Window x:Class="Ticket207621_ChildGridValidation.Window1" 
    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" 
    Title="Window1" Height="300" Width="300"
    <Grid> 
        <telerik:RadGridView Name="RadGridView1" AutoGenerateColumns="false"
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn HeaderText="Sender" DataMemberBinding="{Binding Sender}" /> 
                <telerik:GridViewDataColumn HeaderText="Subject" DataMemberBinding="{Binding Subject}"/> 
                <telerik:GridViewDataColumn HeaderText="Size" DataMemberBinding="{Binding Size}"/> 
            </telerik:RadGridView.Columns> 
            <telerik:RadGridView.HierarchyChildTemplate> 
                <DataTemplate> 
                    <telerik:GridViewDataControl CellValidating="RadGridView_CellValidating"/> 
                </DataTemplate> 
            </telerik:RadGridView.HierarchyChildTemplate> 
        </telerik:RadGridView> 
    </Grid> 
</Window> 
 

Perform the validation needed in the event handler:

        private void RadGridView_CellValidating(object sender, GridViewCellValidatingEventArgs e) 
        { 
            e.IsValid = false
            string newValue = e.NewValue as string
            if (!string.IsNullOrEmpty(newValue)) 
            { 
                // Perform your real-life validation here, mine is dummy 
                if (newValue.EndsWith(".txt")) 
                    e.IsValid = true
            } 
        } 
 

I have attached a small sample project that will get you started. Please, do not hesitate to contact us again if you have any other questions.

Regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marty
Top achievements
Rank 1
answered on 24 Apr 2009, 12:51 PM
Thank you, that did the trick! 

Off topic, kind of: would you happen to know how I can all a similiar method to BeginInsert() but on the child grid from codebehind?  Is it possible?

Thanks,
Marty
0
Hristo Deshev
Telerik team
answered on 25 Apr 2009, 04:10 PM
Hi Marty,

I just posted a solution to this problem to this forum thread.

Best wishes,
Hristo Deshev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marty
Top achievements
Rank 1
answered on 04 May 2009, 01:10 PM
Thank you, I'll check it out.

Sorry for the delay, I was out of town.
Tags
GridView
Asked by
Marty
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Marty
Top achievements
Rank 1
Hristo Deshev
Telerik team
Share this question
or