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

Custom Cell Editor

1 Answer 180 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Sean asked on 11 Nov 2009, 02:09 PM
Hello,
I have a grid with a GridViewDecimalColumn.  When this cell goes into edit mode, I would like to have the regular editor displayed but along side it I want to have a button that the user can click to launch a modal dialog.  I have searched extensively on the forums and I have not found a way to accomplish this with the Decimal column (there appear to be other samples using a gridviewcomboboxcolumn, but I could not adapt that to meet my needs).  FYI - I am using the 2009 Q2 SP1 release.

Any help is greatly appreciated.

Thanks,
Sean

 

1 Answer, 1 is accepted

Sort by
0
Sean
Top achievements
Rank 1
answered on 16 Nov 2009, 01:14 PM
I ended up creating a support ticket for this, and with the help of the folks at Telerik was able to arrive at a solution.  So I though I would post the solution here for anyone who is interested.

 Private Sub rgvLines_CreateCell(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.GridViewCreateCellEventArgs) Handles rgvLines.CreateCell  
          
        If TypeOf (e.Row) Is GridDataRowElement AndAlso _  
            e.Column.HeaderText = "Unit $" Then 
 
            Dim unitPriceCell As New UnitSellingPriceCell(e.Column, e.Row)  
            AddHandler unitPriceCell.ShowPriceBox, AddressOf ShowPriceBoxClicked  
 
            e.CellElement = unitPriceCell  
 
        End If 
 
    End Sub 

Public Class UnitSellingPriceCell  
    Inherits GridDataCellElement  
 
    Private Const _buttonWidth As Integer = 20  
    Private Const _buttonPadding As Integer = 2  
 
    Private _priceBoxButton As RadButtonElement  
 
    Public Event ShowPriceBox()  
 
    Public Sub New(ByVal column As GridViewColumn, ByVal row As GridRowElement)  
 
        MyBase.New(column, row)  
 
    End Sub 
 
    Protected Overloads Overrides Sub CreateChildElements()  
 
        MyBase.CreateChildElements()  
 
        _priceBoxButton = New RadButtonElement()  
 
        With _priceBoxButton  
 
            .ButtonFillElement.Visibility = ElementVisibility.Hidden  
            .BorderElement.Visibility = ElementVisibility.Hidden  
            .Image = My.Resources.operation_VnP  
            .Visibility = ElementVisibility.Collapsed  
 
        End With 
 
        AddHandler _priceBoxButton.Click, AddressOf PriceBoxButtonClick  
 
        Me.Children.Add(_priceBoxButton)  
 
    End Sub 
 
    Protected Overloads Overrides Function ArrangeOverride(ByVal finalSize As SizeF) As SizeF  
        MyBase.ArrangeOverride(finalSize)  
 
        Dim rect As RectangleF = GetClientRectangle(finalSize)  
        Dim rectEdit As New RectangleF(rect.X, rect.Y, rect.Width - (_buttonWidth + _buttonPadding), rect.Height)  
        Dim rectButton As New RectangleF(rectEdit.Right + _buttonPadding, rectEdit.Y, _buttonWidth, rect.Height)  
 
        If Me.GridControl.IsInEditMode AndAlso _  
            TypeOf (Me.GridControl.CurrentCell) Is UnitSellingPriceCell Then 
 
            'We are editing the UnitSellingPrice cell, make sure the pricebox button is visible  
            _priceBoxButton.Visibility = ElementVisibility.Visible  
 
            If Me.Children.Count = 2 Then 
 
                Me.Children(0).Arrange(rectButton)  
                Me.Children(1).Arrange(rectEdit)  
 
            End If 
 
        Else 
 
            'UnitSellingPrice cell is not being edited, hide the price box button  
            _priceBoxButton.Visibility = ElementVisibility.Collapsed  
 
        End If 
 
        Return finalSize  
 
    End Function 
 
    Private Sub PriceBoxButtonClick(ByVal sender As ObjectByVal e As EventArgs)  
 
        RaiseEvent ShowPriceBox()  
 
    End Sub 
 
End Class 

Tags
GridView
Asked by
Sean
Top achievements
Rank 1
Answers by
Sean
Top achievements
Rank 1
Share this question
or