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

2 questions: Master-Details and validation.

3 Answers 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
zoharp
Top achievements
Rank 1
zoharp asked on 30 Aug 2012, 10:26 AM
Hi.
My first question is about Master-Details grid:
I've created a hirarchial grid where the details table is a many-to-many junction talbe (i.e - master is custumers, details is customerToProduct) and all the details have is a single dropdown column with the name of the detail.

My problem is that if I set the AutoGenerateEditColumn to True, I also get an Edit column in the details grid, that I don't want.
My question is How can I set the edit column only for the master table?


My second question is about validation. I used the code examples provided by telerik to add a RequiredFieldValidator to a textBox column, and with a little t & e managed to adapt it also to Numeric columns and DateTime columns.
Now I have 3 methods, each for every column type mentioned about (text, numeric, and datetime).
My problem with that is that all of these 3 methods have almost the exact same code, except for the editor part - see attached snippet:

If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then
        Dim item As GridEditableItem = CType(e.Item, GridEditableItem)
        Dim editor As GridTextBoxColumnEditor = CType(item.EditManager.GetColumnEditor("ContactName"), GridTextBoxColumnEditor) 
        Dim cell As TableCell = CType(editor.TextBoxControl.Parent, TableCell)
        Dim validator As RequiredFieldValidator = New RequiredFieldValidator
       
editor.TextBoxControl.ID = "ID_for_validation"
        validator.ControlToValidate = editor.TextBoxControl.ID

        validator.ErrorMessage = "*"
        cell.Controls.Add(validator)
    End If

for Numeric column I use Dim editor As GridNumericColumnEditor = CType(item.EditManager.GetColumnEditor(ColumnUniqueName), GridNumericColumnEditor)
and for DateTime column I use Dim editor As GridDateTimeColumnEditor = CType(item.EditManager.GetColumnEditor(ColumnUniqueName), GridDateTimeColumnEditor)

My question is how can I use a single method to attach a required field validator to all kinds of built-in columns of the grid?

3 Answers, 1 is accepted

Sort by
0
zoharp
Top achievements
Rank 1
answered on 31 Aug 2012, 06:14 AM
Update: first question solved - simply not check the autoGenerateEdit column and add one manually.

Second question, however, still looking for the answer.
0
Marin
Telerik team
answered on 04 Sep 2012, 07:47 AM
Hi,

 About the second question you do not necessarily need to use the grid's column editors. You can access the cell directly from the item by using the column unique name:

Dim cell As TableCell = item("column unique name")

Once you have the cell you can check how many controls it has and which one is the control that you need (e.g. textbox, datepicker, combobox, etc,). You can easily access it's ID and set it to the validator control:
'if the control is the first one:
Dim id = cell.Controls(0).ID
validator.ControlToValidate = id;


Kind regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
zoharp
Top achievements
Rank 1
answered on 04 Sep 2012, 09:55 AM
Hi Martin,
Thanks for your reply
I think I can take if from there.
Tags
Grid
Asked by
zoharp
Top achievements
Rank 1
Answers by
zoharp
Top achievements
Rank 1
Marin
Telerik team
Share this question
or