DataGridComboBoxColumn Problem with NoKeyUpCombo

Hi

=====================

Option Strict Off
Option Explicit On

Imports System
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms

Namespace DataGridCombobox

    '
    ' Derive a custom column style from DataGridTextBoxColumn that:
    '  - adds a ComboBox member
    '  - tracks when the combobox has focus in the Enter and Leave events
    '  - overrides Edit event so the ComboBox replaces the TextBox
    '  - overrides Commit event to save the changed data
    '

    Public Class DataGridComboBoxColumn

#Region " Declarations "

        Inherits DataGridTextBoxColumn

        Public ColumnComboBox As NoKeyUpCombo 'error here

        Private mcmSource As System.Windows.Forms.CurrencyManager
        Private mintRowNum As Integer
        Private mblnEditing As Boolean

#End Region

#Region " Constructor "

        Public Sub New()

            mcmSource = Nothing
            mblnEditing = False

            ColumnComboBox = New NoKeyUpCombo 'error here

            ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList

            AddHandler ColumnComboBox.Leave, AddressOf LeaveComboBox
            AddHandler ColumnComboBox.SelectionChangeCommitted, AddressOf ComboStartEditing

        End Sub

#End Region

#Region " Private Methods "

        Private Sub HandleScroll(ByVal sender As Object, ByVal e As EventArgs)

            If ColumnComboBox.Visible Then ColumnComboBox.Hide()

        End Sub

        Private Sub ComboStartEditing(ByVal sender As Object, ByVal e As EventArgs)

            mblnEditing = True
            MyBase.ColumnStartedEditing(sender)

        End Sub

        Private Sub LeaveComboBox(ByVal sender As Object, ByVal e As EventArgs)

            If mblnEditing Then
                SetColumnValueAtRow(mcmSource, mintRowNum, ColumnComboBox.Text)
                mblnEditing = False
                Invalidate()
            End If

            ColumnComboBox.Hide()
            AddHandler Me.DataGridTableStyle.DataGrid.Scroll, New EventHandler(AddressOf HandleScroll)

        End Sub

#End Region

#Region " Overridden Methods "

        Protected Overloads Overrides Sub Edit( _
                    ByVal [source] As System.Windows.Forms.CurrencyManager, _
                    ByVal rowNum As Integer, _
                    ByVal bounds As System.Drawing.Rectangle, _
                    ByVal [readOnly] As Boolean, _
                    ByVal instantText As String, _
                    ByVal cellIsVisible As Boolean)

            MyBase.Edit([source], rowNum, bounds, [readOnly], instantText, cellIsVisible)

            mintRowNum = rowNum
            mcmSource = [source]

            With ColumnComboBox
                .Parent = Me.TextBox.Parent
                .Location = Me.TextBox.Location
                .Size = New Size(Me.TextBox.Size.Width, .Size.Height)
                .SelectedIndex = .FindStringExact(Me.TextBox.Text)
                .Text = Me.TextBox.Text

                Me.TextBox.Visible = False
                .Visible = True

                AddHandler Me.DataGridTableStyle.DataGrid.Scroll, AddressOf HandleScroll

                .BringToFront()
                .Focus()
            End With

        End Sub

        Protected Overrides Function Commit( _
                    ByVal dataSource As System.Windows.Forms.CurrencyManager, _
                    ByVal rowNum As Integer) As Boolean

            If mblnEditing Then
                mblnEditing = False
                SetColumnValueAtRow(dataSource, rowNum, ColumnComboBox.Text)
            End If

            Return True

        End Function

        Protected Overrides Sub ConcedeFocus()

            Console.WriteLine("ConcedeFocus")
            MyBase.ConcedeFocus()

        End Sub

        Protected Overrides Function GetColumnValueAtRow( _
                    ByVal [source] As System.Windows.Forms.CurrencyManager, _
                    ByVal rowNum As Integer) As Object

            Dim s As Object = MyBase.GetColumnValueAtRow([source], rowNum)
            Dim dv As DataView = CType(Me.ColumnComboBox.DataSource, DataView)
            Dim rowCount As Integer = dv.Count
            Dim i As Integer = 0
            Dim obj As Object

            While i < rowCount
                obj = dv(i)(Me.ColumnComboBox.ValueMember)
                If (Not obj Is DBNull.Value) AndAlso _
                   (Not s Is DBNull.Value) AndAlso _
                   (s = obj) Then

                    Exit While
                End If

                i += 1
            End While

            If i < rowCount Then
                Return dv(i)(Me.ColumnComboBox.DisplayMember)
            End If

            Return DBNull.Value

        End Function

        Protected Overrides Sub SetColumnValueAtRow( _
                    ByVal [source] As System.Windows.Forms.CurrencyManager, _
                    ByVal rowNum As Integer, ByVal value As Object)

            Dim s As Object = value
            Dim dv As DataView = CType(Me.ColumnComboBox.DataSource, DataView)
            Dim rowCount As Integer = dv.Count
            Dim i As Integer = 0
            Dim obj As Object

            While i < rowCount
                obj = dv(i)(Me.ColumnComboBox.DisplayMember)

                If (Not obj Is DBNull.Value) AndAlso _
                    (s = obj) Then

                    Exit While
                End If

                i += 1
            End While

            If i < rowCount Then
                s = dv(i)(Me.ColumnComboBox.ValueMember)
            Else
                s = DBNull.Value
            End If

            MyBase.SetColumnValueAtRow([source], rowNum, s)
        End Sub

#End Region

    End Class

End Namespace
==============================================


I am using the above class to add a combobox to a datagrid.  I have used this class before and worked fine.   My problem is that it now tells me i have this error!

Type 'NoKeyUpCombo' is not defind. on these lines

Public ColumnComboBox As NoKeyUpCombo 'error here
ColumnComboBox = New NoKeyUpCombo 'error here


Can anyone see what my class is missing or post me a new DataGridComboBoxColumn  to perform this function.

Thanks
Nerdy_Girl88Asked:
Who is Participating?
 
RonaldBiemansConnect With a Mentor Commented:
Hi nerdy_girl88,

The first and obvious question, is the nokeyupcombo class in your project

Option Strict Off
Option Explicit On

Imports Microsoft.VisualBasic
Imports System
Imports System.ComponentModel
Imports System.Data
Imports System.Data.Common
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Windows.Forms

Namespace DataGridTextBoxCombo
    Public Class NoKeyUpCombo
        Inherits ComboBox
        Private WM_KEYUP As Integer = &H101


        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            If m.Msg = WM_KEYUP Then
                Return
            End If
            MyBase.WndProc(m)
        End Sub
    End Class
End Namespace
0
 
Nerdy_Girl88Author Commented:
Your right it wasn;t, silly, just addeed it now i get this error

Specific cast is not valid!

The program runs but when i Click on any control i get this error,  

thanks.
0
 
RonaldBiemansCommented:
Could you specify where the error occurs in your code (set
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
Nerdy_Girl88Author Commented:
it appears at the being of my frmAccessory class.  This is the class that has all the controls on it, including the datagrid with the new combobox column.  The error is highlighted green, I don't know how to deal with these error messages.

I have a from called frmAccessory.

Imports Quote_a_matic2000.DataGridCombobox
Public Class frmAccessory   //this is the line i get the error on.
    Inherits System.Windows.Forms.Form
'code in here
  End Sub
End Class

thanks
0
 
Nerdy_Girl88Author Commented:
I just stepped through me code and noticed it happened here

Private Sub cboSearch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboSearch.SelectedIndexChanged
        Dim DsAccessory As DataSet
        Dim Parameter As String

        If mFinished Then
            'fill the dataset with data
            Parameter = cboSearch.SelectedValue
            DsAccessory = mDataobj.getAccessory(Parameter)
        End If
    End Sub    //error here
End Class

it jumps to here......Public Class frmAccessory   and highlights frmAccessory, and displays this error.    //this is the line i get the error on.

An unhandled exception of type 'System.InvalidCastException' occurred in system.windows.forms.dll
0
 
Nerdy_Girl88Author Commented:
is it because the cast type expected in the DataGridComboBoxColumn class is expecting that datagrid.datasource to be a dataview?
0
 
RonaldBiemansCommented:
I think it is, because of this line

Dim dv As DataView = CType(Me.ColumnComboBox.DataSource, DataView)
0
 
Nerdy_Girl88Author Commented:
The datagrid on my form is  part of a master detail form, i want to be able to update,Add and delete from the dataset!  

Is there cose i can use to modify this function to use a dataset.

0
 
RonaldBiemansCommented:
Hi Nerdy_Girl88,

What has updating,adding and deleting from the dataset have to do with how you fill your combobox ?

how do you fill the combobox now ?
0
 
Nerdy_Girl88Author Commented:
Your right it doesn't,  I was thinking the dataview would need to be updated.  I Now realise that the combobox has a daview. And the datagrid has its own dataset that is bound to it.  I get very confused using all these different objects.  Thanks for you help.

The combobox works fine now, i just changed the datasource to a dataview.

Thanks.
0
All Courses

From novice to tech pro — start learning today.