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

Custom grid editor

6 Answers 269 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sonny Chouinard
Top achievements
Rank 1
Sonny Chouinard asked on 05 Mar 2010, 02:46 PM
I'm currently evaluating your product.

In the grid we are currently using, we use custom editor. These editor are controls and user control that we created and that we are using everywhere in the application. We would like to be able to use these same control in the RadGridView, but we can only use RadElement.

Is there a way to use our company control as editor in grid?

Is there plan to make an interface ex: IRadElement, that will make us possible to use any of our control in the grid.

Thank you for your reply.

6 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 05 Mar 2010, 03:50 PM
Hi Jonathan GrandMaison,

Yes, this is possible. You should host your control inside RadHostItem element. There is an example about how to create custom editors in RadGridView in our Demo application. You can find more details in our online help. If you send me your application, I will be glad to assist you further.

Should you have any other questions, don't hesitate to ask.

All the best,
Jack
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
Sonny Chouinard
Top achievements
Rank 1
answered on 08 Mar 2010, 03:45 PM
Thank you for your reply, i will try with the RadHostItem and see how it works.
0
Sonny Chouinard
Top achievements
Rank 1
answered on 08 Mar 2010, 07:30 PM
I have managed to add my custom Combobox in the grid as an editor but I still have a problem.
When i press the dropDown button, the combobox list show and close immediately.

What did i do wrong?

Editor element
Imports Telerik.WinControls.UI 
Imports Telerik.WinControls 
 
Public Class TestEditor2Element 
    Inherits RadHostItem 
 
    Private WithEvents cboCustom As Custom.Controls.ComboBox 
    Public Event ValueChanged(ByVal sender As ObjectByVal e As EventArgs) 
 
    Public Sub New(ByVal ctrl As Custom.Controls.ComboBox) 
        MyBase.New(ctrl) 
        cboCustom= ctrl 
        Me.CanFocus = True 
    End Sub 
 
 
    Public Property Value() As Object 
        Get 
            Return cboCustom.SelectedValue 
        End Get 
        Set(ByVal value As Object
            cboCustom.SelectedValue = value 
        End Set 
    End Property 
 
    Private Sub cboCustom_ValueChanged(ByVal sender As ObjectByVal e As EventArgs) Handles cboCustom.SelectedValueChanged 
        RaiseEvent ValueChanged(sender, e) 
    End Sub 
End Class 
 

Grid editor
Imports Telerik.WinControls.UI 
Imports Telerik.WinControls 
 
Public Class TestEditor2 
    Inherits BaseGridEditor 
 
    Private WithEvents m_cboCustom As Custom.Controls.ComboBox 
 
    Public Overrides Property Value() As Object 
        Get 
            Dim editor As TestEditor2Element = CType(Me.EditorElement, TestEditor2Element) 
            Return editor.Value 
        End Get 
 
        Set(ByVal value As Object
            Dim editor As TestEditor2Element = CType(Me.EditorElement, TestEditor2Element) 
            If value IsNot Nothing AndAlso value IsNot DBNull.Value Then 
                editor.Value = value 
            Else 
                editor.Value = DBNull.Value 
            End If 
        End Set 
    End Property 
 
    Public Overrides Sub BeginEdit() 
        MyBase.BeginEdit() 
        m_cboCustom.Focus() 
 
        AddHandler (CType(EditorElement, TestEditor2Element)).ValueChanged, AddressOf cboValueChanged 
    End Sub 
 
    Public Overrides Function EndEdit() As Boolean 
        AddHandler (CType(EditorElement, TestEditor2Element)).ValueChanged, AddressOf cboValueChanged 
        Return MyBase.EndEdit() 
    End Function 
 
    Private Sub cboValueChanged(ByVal sender As ObjectByVal e As EventArgs) 
        OnValueChanged() 
    End Sub 
 
    Protected Overrides Function CreateEditorElement() As RadElement 
        Return New TestEditor2Element(m_cboCustomcboCustom) 
 
    End Function 
 
    Public Sub New(ByVal ctrl As Custom.Controls.ComboBox) 
        MyBase.New() 
        m_cboCustom = ctrl 
    End Sub 
 
 
 
End Class 

Form
Public Class frmGridEdition 
 
    Dim m_dsData As DataSet 
    Dim m_dtReferentiel As DataTable 
    Dim m_objEditor As TestEditor2 
 
    Private Sub frmGridEdition_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load 
 
        m_dsData = ReqFormGetRequest(traTransaction, 78742) 
        m_dtReferentiel = DatabaseHelper.ExecuteDataTable(traTransaction, CommandType.Text, "Select * from Intervenant"
 
        cboEditor1.ValueMember = "ikintervenant" 
        cboEditor1.DisplayMember = "cinterv" 
        cboEditor1.DataSource = m_dtReferentiel 
 
 
        m_objEditor = New TestEditor2(cboEditor1) 
 
        grdInterv.DataMember = "interventions_associees" 
        grdInterv.DataSource = m_dsData 
 
 
        grdInterv.Refresh() 
 
    End Sub 
 
    Private Sub grdInterv_EditorRequired(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.EditorRequiredEventArgs) Handles grdInterv.EditorRequired 
        If grdInterv.CurrentColumn.HeaderText = "Editor1" Then 
            e.Editor = DirectCast(m_objEditor, Telerik.WinControls.UI.IValueEditor) 
        End If 
 
    End Sub 
 
End Class 

0
Svett
Telerik team
answered on 09 Mar 2010, 01:21 PM
Hello Jonathan GrandMaison,

Your approach is right. You need only to turn off routing of messages in RadHostItem element. So you need only to override InitializeFields method of RadHostItem and do the following:

Protected Overrides Sub InitializeFields()
    MyBase.InitializeFields()
    Me.RouteMessages = False
End Sub

Also I recommend you do a small change in EndEdit method of TestEditor2 class. To prevent a memory leak you should unsubscribe from ValueChanged event.

Public Overrides Function EndEdit() As Boolean
    RemoveHandler (CType(EditorElement, TestEditor2Element)).ValueChanged, AddressOf cboValueChanged
    Return MyBase.EndEdit()
End Function

If you have further questions do not hesitate to write us back.

Greetings,
Svett
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
Sonny Chouinard
Top achievements
Rank 1
answered on 12 Mar 2010, 05:51 PM
There is on small problem left.

If my combobox data look like this:

Key         Display
1             Desc1
2             Desc2
3             Desc3

and i select "Desc2", when i exit the editor, the value displayed in the grid is the value "2" instead of the description "Desc2". Is there a property I must overrides to be able to show the description?


0
Svett
Telerik team
answered on 16 Mar 2010, 03:47 PM
Hi Jonathan GrandMaison,

The GridComboBoxCellElement properties depend on the ValueMember and DisplayMember of GridViewComboBoxColumn. The text of the cell is a value determined by the value of the DisplayMember, the value of the cell is determined by the value of the ValueMember.

If you still need assistance, please post a sample code snippet that demonstrates how you create and bind GridViewComboBoxColumn.

Sincerely yours,
Svett
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
Sonny Chouinard
Top achievements
Rank 1
Answers by
Jack
Telerik team
Sonny Chouinard
Top achievements
Rank 1
Svett
Telerik team
Share this question
or