I want to set the AutoCompleteMode property in ApplyCellStyleToEditingControl subroutine

Posted by Ranjan Gupta on Stack Overflow See other posts from Stack Overflow or by Ranjan Gupta
Published on 2010-12-22T08:50:14Z Indexed on 2010/12/22 8:54 UTC
Read the original article Hit count: 275

Filed under:

Hi,

I am creating a DataGridView Column. and it is working well. now I want to customise this column with AutoCompleteMode, and AutoCompleteSource properties to show the customised data. I made the properties for this columns, and these are also working well. but these properties are not working in the "ApplyCellStyleToEditingControl" subroutine.

Please help me to use these column properties in the "ApplyCellStyleToEditingControl" subroutine.

Public Class DataGridViewDataValueColumn
    Inherits DataGridViewColumn

    Dim m_AutoCompleteMode As AutoCompleteMode, _
        m_AutoCompleteSource As AutoCompleteSource, _
        m_AutoCompleteStringCollection As AutoCompleteStringCollection

    Public Sub New()
        MyBase.New(New DataValueCell())
    End Sub

    Public Overrides Property CellTemplate() As DataGridViewCell
        Get
            Return MyBase.CellTemplate
        End Get
        Set(ByVal value As DataGridViewCell)

            ' Ensure that the cell used for the template is a DataValueCell.
            If (value IsNot Nothing) AndAlso _
                Not value.GetType().IsAssignableFrom(GetType(DataValueCell)) _
                Then
                Throw New InvalidCastException("Must be a DataValueCell")
            End If
            MyBase.CellTemplate = value

        End Set
    End Property

Region "User Defined Properties"

    '&*--------------------------------------*&'
    <Description("Indicates the text completion behaviour of the combo box."), DefaultValue(AutoCompleteMode.None)> _
    Public Property AutoCompleteMode() As AutoCompleteMode
        Get
            Return m_AutoCompleteMode
        End Get
        Set(ByVal value As AutoCompleteMode)
            m_AutoCompleteMode = value
        End Set
    End Property

    <Description("The source of complete strings used to automatic completion."), DefaultValue(AutoCompleteSource.None)> _
    Public Property AutoCompleteSource() As AutoCompleteSource
        Get
            Return m_AutoCompleteSource
        End Get
        Set(ByVal value As AutoCompleteSource)
            m_AutoCompleteSource = value
        End Set
    End Property

    <Description("The autocomplete custom source.")> _
    Public Property AutoCompleteCustomSource() As AutoCompleteStringCollection
        Get
            Return m_AutoCompleteStringCollection
        End Get
        Set(ByVal value As AutoCompleteStringCollection)
            m_AutoCompleteStringCollection = value
        End Set
    End Property

End Region

End Class

'&*--------------------------------------*&'
Class DataValueCell
    Inherits DataGridViewTextBoxCell

    Public Sub New()
        '
    End Sub

    Public Overrides ReadOnly Property EditType As Type
        Get
            Return GetType(PCLDataGridViewTextBoxEditingControl)
        End Get
    End Property

End Class

'&*--------------------------------------*&'
'&* Edit DataGridView Columns            *&'
'&*--------------------------------------*&'
Class PCLDataGridViewTextBoxEditingControl
    Inherits DataGridViewTextBoxEditingControl

    Public Overrides Function EditingControlWantsInputKey(ByVal keyData As Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean
        Select Case ((keyData And Keys.KeyCode))
            Case Keys.Prior, Keys.Next, Keys.End, Keys.Home, Keys.Left, Keys.Up, Keys.Right, Keys.Down, Keys.Delete
                Return True
        End Select
        Return MyBase.EditingControlWantsInputKey(keyData, dataGridViewWantsInputKey)
    End Function

    Public Overrides Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As DataGridViewCellStyle)
        With DirectCast(Me, TextBox)
            '.AutoCompleteMode = DataGridViewDataValueColumn.AutoCompleteMode_Value
            '.AutoCompleteSource = DataGridViewDataValueColumn.AutoCompleteSource_Value
            '.AutoCompleteCustomSource = MyBase.AutoCompleteCustomSource
        End With
    End Sub

End Class

© Stack Overflow or respective owner

Related posts about .NET