473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Custom ComboBox Problems

Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing into
the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the selected
index is correct, but if i check the value after that it
is set to the previous value. if i select item one, the
value is -1, if i then select item 3 the value is 1. If i
remove the code to drop down the list the value is correct.

It sounds similar to a problem mark was having on Jan 7th,
only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = -1))
Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text field,
a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()
{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange"
, "Pineapple", "Pineberries", "Pinenuts", "Strawberries"})
Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " & Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class
Nov 20 '05 #1
5 2127
Hi,

They showed how to make one in a vbtv episode. Here is a link to
the code.
http://www.gotdotnet.com/Community/U...a-09bc8fd2860b

Ken
------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote in message
news:60****************************@phx.gbl...
Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing into
the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the selected
index is correct, but if i check the value after that it
is set to the previous value. if i select item one, the
value is -1, if i then select item 3 the value is 1. If i
remove the code to drop down the list the value is correct.

It sounds similar to a problem mark was having on Jan 7th,
only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = -1))
Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text field,
a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()
{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange"
, "Pineapple", "Pineberries", "Pinenuts", "Strawberries"})
Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " & Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class

Nov 20 '05 #2
Hi Ken,

if i add the code,

Me.DroppedDown = True

to the keypress event in this component i get the same
undesireable behavior.

ross
-----Original Message-----
Hi,

They showed how to make one in a vbtv episode. Here is a link tothe code.
http://www.gotdotnet.com/Community/U...es/Details.asp x?SampleGuid=30138e02-c2c3-41cd-bc6a-09bc8fd2860b
Ken
------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote in messagenews:60****************************@phx.gbl...
Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing into the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the selected index is correct, but if i check the value after that it
is set to the previous value. if i select item one, the
value is -1, if i then select item 3 the value is 1. If i remove the code to drop down the list the value is correct.
It sounds similar to a problem mark was having on Jan 7th, only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = - 1)) Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text field, a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()
{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange" , "Pineapple", "Pineberries", "Pinenuts", "Strawberries" }) Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " & Me.SelectableComboBox1.SelectedIndex End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class

.

Nov 20 '05 #3
Hi,

untested
http://www.thecodeproject.com/vb/net...e_combobox.asp

Ken
--------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote in message
news:5b****************************@phx.gbl...
Hi Ken,

if i add the code,

Me.DroppedDown = True

to the keypress event in this component i get the same
undesireable behavior.

ross
-----Original Message-----
Hi,

They showed how to make one in a vbtv episode.

Here is a link to
the code.
http://www.gotdotnet.com/Community/U...es/Details.asp

x?SampleGuid=30138e02-c2c3-41cd-bc6a-09bc8fd2860b

Ken
------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote

in message
news:60****************************@phx.gbl...
Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing into the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the selected index is correct, but if i check the value after that it
is set to the previous value. if i select item one, the
value is -1, if i then select item 3 the value is 1. If i remove the code to drop down the list the value is correct.
It sounds similar to a problem mark was having on Jan 7th, only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = - 1)) Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text field, a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()
{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange" , "Pineapple", "Pineberries", "Pinenuts", "Strawberries" }) Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " & Me.SelectableComboBox1.SelectedIndex End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class

.

Nov 20 '05 #4
Not exactly what i was looking for. Half the time
pressing 'A' will get you Apple with the cursor at the end
of the word and half the time it will select 'Apple' with
a selection and the cursor before the 1st 'p' (what i
would expect).

Looks like it is also be providing the previous
selectedIndex when the list drops down which has been my
problem.

thx,

ross
-----Original Message-----
Hi,

untested
http://www.thecodeproject.com/vb/net...plete_combobox ..asp
Ken
--------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote in messagenews:5b****************************@phx.gbl...
Hi Ken,

if i add the code,

Me.DroppedDown = True

to the keypress event in this component i get the same
undesireable behavior.

ross
-----Original Message-----
Hi,

They showed how to make one in a vbtv episode.

Here is a link to
the code.
http://www.gotdotnet.com/Community/U...ples/Details.a sp
x?SampleGuid=30138e02-c2c3-41cd-bc6a-09bc8fd2860b

Ken
------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote

in message
news:60****************************@phx.gbl.. .
Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing

into
the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the

selected
index is correct, but if i check the value after that
it is set to the previous value. if i select item one, the value is -1, if i then select item 3 the value is 1.

If i
remove the code to drop down the list the value is

correct.

It sounds similar to a problem mark was having on Jan

7th,
only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = -
1))
Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text

field,
a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component

list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As

System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer. 'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()

{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange"
, "Pineapple", "Pineberries", "Pinenuts", "Strawberrie s" })
Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender

As System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " &

Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class


.

.

Nov 20 '05 #5
I worked around the initial problem by setting a public
variable in the leave and selectedindexchanged events
which i can access instead of selectedindex.

I am still having the same problem that the leave event is
not firing if the user clicks off the combobox while the
dropdown list is displayed.

Any help would be greatly appreciated!
-----Original Message-----
Hi,

untested
http://www.thecodeproject.com/vb/net...plete_combobox ..asp
Ken
--------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote in messagenews:5b****************************@phx.gbl...
Hi Ken,

if i add the code,

Me.DroppedDown = True

to the keypress event in this component i get the same
undesireable behavior.

ross
-----Original Message-----
Hi,

They showed how to make one in a vbtv episode.

Here is a link to
the code.
http://www.gotdotnet.com/Community/U...ples/Details.a sp
x?SampleGuid=30138e02-c2c3-41cd-bc6a-09bc8fd2860b

Ken
------------------
"ross kerr" <an*******@discussions.microsoft.com> wrote

in message
news:60****************************@phx.gbl.. .
Hi All,

I am extending the combobox to create a control that
selects an item based on the text the user is typing

into
the text area of the control.

I have an issue that occurs only when i drop down the
combo box as the users typing.

When the on leave event is fired the value in the

selected
index is correct, but if i check the value after that
it is set to the previous value. if i select item one, the value is -1, if i then select item 3 the value is 1.

If i
remove the code to drop down the list the value is

correct.

It sounds similar to a problem mark was having on Jan

7th,
only this doesn't involve data binding.

Any help would be much appreciated.

Thanks,

ross (rkerratbaileyind.com)

Code to follow:

Here is the code for the custom combobox.

Public Class SelectingComboBox
Inherits System.Windows.Forms.ComboBox

Public LimitToList As Boolean = True

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'UserControl1 overrides dispose to clean up the
component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Protected Overloads Overrides Sub OnKeyPress(ByVal
evt As Windows.Forms.KeyPressEventArgs)
If (evt.KeyChar.ToString = Chr
(Windows.Forms.Keys.Back) _
Or evt.KeyChar.ToString < Chr(32) _
Or evt.KeyChar.ToString > Chr(127)) Then
MyBase.OnKeyPress(evt)
Exit Sub
End If

Me.DroppedDown = True
Dim oldText, newText As String
oldText = Me.Text.Substring(0,
Me.SelectionStart)

If (evt.KeyChar.ToString = Chr(8)) Then
Try
Me.Text = oldText.Substring
(0, oldText.Length - 1)

Catch e2 As System.Exception
Me.Text = ""
Me.SelectedIndex = -1
Exit Sub
End Try

If (Me.Text.Length = 0) Then
Me.SelectedIndex = -1
Exit Sub
End If

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart =
oldText.Length - 1
Else
If ((Me.LimitToList = True) And
(Me.FindString(oldText + evt.KeyChar.ToString(), 0) = -
1))
Then
evt.Handled = True
Exit Sub
End If

Me.Text = oldText +
evt.KeyChar.ToString()

newText = Me.Text
Me.SelectedIndex = -1
Me.Text = newText

Me.SelectedIndex = Me.FindString
(Me.Text, 0)
Me.SelectionStart = oldText.Length
+ 1

End If

If (Me.Text.Length > Me.SelectionStart)
Then
Me.SelectionLength =
(Me.Text.Length - Me.SelectionStart)
End If

evt.Handled = True

End Sub

Protected Overloads Overrides Sub onleave(ByVal
evt As System.EventArgs)
MyBase.onleave(evt)
Me.Refresh()
End Sub

Protected Overloads Overrides Sub
onSelectedIndexChanged(ByVal evt As System.EventArgs)
MyBase.onSelectedIndexChanged(evt)
System.Console.WriteLine("Selected
Index: " & Me.SelectedIndex)
End Sub
'Required by the Windows Form Designer
Private components As
System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
components = New
System.ComponentModel.Container
End Sub

#End Region

End Class

Here is the code for the test form. It has a text

field,
a button and the custom combobox component.

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component

list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As

System.ComponentModel.IContainer

'NOTE: The following procedure is required by the
Windows Form Designer
'It can be modified using the Windows Form
Designer. 'Do not modify it using the code editor.
Friend WithEvents SelectableComboBox1 As
VBSelectingComboBox.SelectingComboBox
Friend WithEvents Label1 As
System.Windows.Forms.Label
Friend WithEvents TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.SelectableComboBox1 = New
VBSelectingComboBox.SelectingComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New
System.Windows.Forms.TextBox
Me.Button1 = New
System.Windows.Forms.Button
Me.SuspendLayout()
'
'SelectableComboBox1
'
Me.SelectableComboBox1.Items.AddRange(New
Object()

{"Apple", "Bananna", "Honeydew", "Lemon", "Melon", "Orange"
, "Pineapple", "Pineberries", "Pinenuts", "Strawberrie s" })
Me.SelectableComboBox1.Location = New
System.Drawing.Point(120, 40)
Me.SelectableComboBox1.Name
= "SelectableComboBox1"
Me.SelectableComboBox1.Size = New
System.Drawing.Size(121, 21)
Me.SelectableComboBox1.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New
System.Drawing.Point(16, 40)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size
(88, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Test ComboBox:"
'
'TextBox1
'
Me.TextBox1.Location = New
System.Drawing.Point(88, 160)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size
(104, 20)
Me.TextBox1.TabIndex = 2
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(104, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size
(272, 189)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.SelectableComboBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region
Dim i As Short
Private Sub
SelectableComboBox1_SelectedIndexChanged(ByVal sender

As System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.SelectedIndexChanged
i += 1
Me.Text = "changed " & i & " times.
selected index = " &

Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ComboLeave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
SelectableComboBox1.Leave
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub

Private Sub ButtonClick(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.TextBox1.Text =
Me.SelectableComboBox1.SelectedIndex
End Sub
Private Sub getKeyPress(ByVal sender As Object,
ByVal e As Windows.Forms.KeyPressEventArgs) Handles
Button1.KeyPress, SelectableComboBox1.KeyPress,
TextBox1.KeyPress
If Asc(e.KeyChar) =
System.Windows.Forms.Keys.Return Then
SelectNextControl(sender, True,
True, True, True)
e.Handled = True
End If
End Sub
End Class


.

.

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jean | last post by:
hi: i am developing a custom combobox for my company's needs that is made up of a textbox, listbox, button. i am using c#. everything is fine except for one issue. in a normal combobox,...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
3
by: TT (Tom Tempelaere) | last post by:
Hay there, I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one (I hope .NET 2.0 supplies one). I based it on this article:...
1
by: Marty Cruise | last post by:
I have a custom collection which contains instances of a custom class. With me so far? OK, now I set the datasource of a combobox to the collection, having overridden the ToString() function of...
2
by: Don | last post by:
I've been trying to create a custom collection that can be bound to a combobox via the DataSource property, but I can't seem to get it to work. I've created a class that implements IList, and it...
3
by: Bob | last post by:
Thinking two things, 1- Creating a userControl -yeah you guessed it, a multi column drop down combobox - I've looked at several articles and did not find what I need, one that's bindable and that...
3
by: Richard Ryerson | last post by:
I have a general DataGridComboBoxColumn that I built using the Example in the .NET 2003 Combined Collection help file (that was a data time picker). I am able to assign a data source and display...
8
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
0
by: Mike | last post by:
Hey everyone... I've got three problems with a custom DataGridView column I've built following the "How To: Host Controls in Windows Forms DataGridView Cells" article. The base editing control...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.