[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

DataGridComboBoxColumn Problem with NoKeyUpCombo

Posted on 2004-10-06
10
Medium Priority
?
325 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:Nerdy_Girl88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 2000 total points
ID: 12236166
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
 

Author Comment

by:Nerdy_Girl88
ID: 12236179
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
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12236216
Could you specify where the error occurs in your code (set
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Nerdy_Girl88
ID: 12236253
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
 

Author Comment

by:Nerdy_Girl88
ID: 12236280
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
 

Author Comment

by:Nerdy_Girl88
ID: 12236337
is it because the cast type expected in the DataGridComboBoxColumn class is expecting that datagrid.datasource to be a dataview?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12236382
I think it is, because of this line

Dim dv As DataView = CType(Me.ColumnComboBox.DataSource, DataView)
0
 

Author Comment

by:Nerdy_Girl88
ID: 12236404
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
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12236473
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
 

Author Comment

by:Nerdy_Girl88
ID: 12246065
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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question