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

Costum edit template

5 Answers 192 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steffen
Top achievements
Rank 1
Steffen asked on 17 Mar 2009, 01:57 PM
I was playing around with the trial version and did not notice any transparent way to set a custom edit template for a gridviewdatacolumn. The sample project includes an example of a cell in displaymode but not in editmode.

What's the best practice for making a custon edit template?

5 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 19 Mar 2009, 06:25 PM
Hello Steffen,

I'm attaching a sample application that creates custom editor that simulate "lookup" column.
To create custom editor generally you have to follow these steps:
  1. Create inheritor of the GridViewCellEditor class
  2. Create inheritor of the EditorSettings<T> where T is your custom GridViewCellEditor.
  3. Set EditorSettings property of the GridViewDataColumn object.

We are aiming to create a variety of different columns to make such scenarios easier to implement.

All the best,
Nedyalko Nikolov
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
Steffen
Top achievements
Rank 1
answered on 23 Mar 2009, 03:52 PM
would it be possible to provide an example Silverlight. I undertand that WPF and silverlight are related but I can't get the suggested appoach to work in silverlight.
0
Nedyalko Nikolov
Telerik team
answered on 27 Mar 2009, 02:27 PM
Hello Steffen,

Sorry for my late reply. I needed some more time to prepare an example for Silverlight.

I'm attaching a modified version of the "ForeignKey" example that works for Silverlight. Main differences are related to some bindings that do not work properly in Silverlight and had be manually done.

I hope this will help you. In the near future we plan to introduce a special "ComboBox" column that will handle such scenarios by default.

Best wishes,
Nedyalko Nikolov
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Rogério
Top achievements
Rank 1
answered on 09 May 2009, 07:29 PM
Hello,

Can you give us some examples of bindings that do not work in Silverlight!?

I've extended you samples application to use a custom editor fo booleans (I know yhat GridView already supports it, but I need to do some more stuff)!

The problem is that CellTemplate does not get the "checkbox" IsChecked state from the editor control. This problem only happens for new rows inserted!

Here you have some peace fo my custom editor:
       public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();


            PropertyInfo[] properties = typeof(GridViewCellEditor).GetProperties(BindingFlags.Instance | BindingFlags.Public);
            object editorSettings = (from property in properties
                                     where property.Name == "EditorSettings"
                                     select property).First().GetValue(this, null);


            CheckBox boolControl = this.EditorElement as CheckBox;
            if (boolControl != null)
            {
                boolControl.LostFocus += new RoutedEventHandler(boolControl_LostFocus);

            }
        }

        void boolControl_LostFocus(object sender, RoutedEventArgs e)
        {
            CheckBox checkBox = sender as CheckBox;
            if (checkBox != null)
            {
                this.Value = checkBox.IsChecked;
            }
        }

Regards,
Rogério



0
Nedyalko Nikolov
Telerik team
answered on 13 May 2009, 12:02 PM
Hi Rogério,

I've managed to reproduce the problem. The problem persists only with ValidationMode.Row which is the default ValidationMode for NewRow. Unfortunately some platform (Silverlight) related restrictions do not allow us to fix the issue. Problem can be solved if you can bind IsChecked property directly to the GridViewCell.Value, the case with CellTemplate is that you bind its value directly to the underlying business object which (when ValidationMode == Row) is updated when user commits the row (click on next row).

Good news is that there is a workaround. I suggest you to use more powerful GridViewColumn.CellStyle property. I'm attaching a default style of the GridViewCell which I hope will help you in order just to customize some properties, but leave some important states (for example Editing).

Regards,
Nedyalko Nikolov
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.
Tags
GridView
Asked by
Steffen
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Steffen
Top achievements
Rank 1
Rogério
Top achievements
Rank 1
Share this question
or