PC Review


Reply
Thread Tools Rate Thread

Designer shows combobox but run time does not

 
 
active
Guest
Posts: n/a
 
      19th Feb 2007
I tried to use a datasource with a combobox and it didn't work completely so
I build a small test that was much more straight forward then the app.

The test was to see if the combobox dropdown list displayed the correct
data.

However, although the designer shows the combobox the combobox does not
show at runtime.

If you would be so kind as to cut the code below and paste it into a form
maybe you can easily see why the combobox does not display.



Thanks







Public Class Form1

Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.

<System.Diagnostics.DebuggerNonUserCode()> _

Protected Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing AndAlso components IsNot Nothing Then

components.Dispose()

End If

MyBase.Dispose(disposing)

End Sub

Friend WithEvents ComboBox1 As WindowsApplication1.StringWithIntegerComboBox

'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.

Private Sub InitializeComponent()

Me.ComboBox1 = New WindowsApplication1.StringWithIntegerComboBox

Me.SuspendLayout()

'

'ComboBox1

'

Me.ComboBox1.Location = New System.Drawing.Point(136, 139)

Me.ComboBox1.Name = "ComboBox1"

Me.ComboBox1.Size = New System.Drawing.Size(235, 21)

Me.ComboBox1.TabIndex = 0

'

'Form1

'

Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)

Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font

Me.ClientSize = New System.Drawing.Size(572, 341)

Me.Controls.Add(Me.ComboBox1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

End Class

Public Class StringWithIntegerComboBox

Inherits System.Windows.Forms.ComboBox

Public Sub New()

MyBase.New()

Me.DataSource = myList

Me.DisplayMember = "Str"

Me.ValueMember = "Value"

myList.Add(New StringWithInteger("One", 1))

myList.Add(New StringWithInteger("Two", 2))

myList.Add(New StringWithInteger("Three", 3))

End Sub

Public myList As List(Of StringWithInteger) = New List(Of StringWithInteger)

End Class

Public Class StringWithInteger

Private mInteger As Integer

Private mString As String

Private mToStringDisplaysInteger As Boolean = False

Public Sub New(ByVal str As String, ByVal value As Integer)

mString = str

mInteger = value

End Sub

Public Function Clone() As StringWithInteger

Clone = New StringWithInteger(mString, mInteger)

End Function

Public Overrides Function ToString() As String

If mToStringDisplaysInteger Then

ToString = CStr(mInteger)

Else

ToString = mString

End If

End Function

Public Property Str() As String

Get

Str = mString

End Get

Set(ByVal text As String)

mString = text

End Set

End Property

Public Property ToStringDisplaysSingle() As Boolean

Get

ToStringDisplaysSingle = mToStringDisplaysInteger

End Get

Set(ByVal displayInteger As Boolean)

mToStringDisplaysInteger = displayInteger

End Set

End Property

Public Property Value() As Integer

Get

Value = mInteger

End Get

Set(ByVal numb As Integer)

mInteger = numb

End Set

End Property

End Class


 
Reply With Quote
 
 
 
 
Lloyd Sheen
Guest
Posts: n/a
 
      19th Feb 2007
Sorry don't have access to VS but it seems that you are adding the entries
after you bind the list to the combobox. Try it the other way or refresh
the combobox after you add the entries. I don't think that adding will
automatically cause the control to know there are entries. When you bound
the list was empty.

Lloyd Sheen
" active" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I tried to use a datasource with a combobox and it didn't work completely
>so I build a small test that was much more straight forward then the app.
>
> The test was to see if the combobox dropdown list displayed the correct
> data.
>
> However, although the designer shows the combobox the combobox does not
> show at runtime.
>
> If you would be so kind as to cut the code below and paste it into a form
> maybe you can easily see why the combobox does not display.
>
>
>
> Thanks
>
>
>
>
>
>
>
> Public Class Form1
>
> Inherits System.Windows.Forms.Form
>
> 'Form overrides dispose to clean up the component list.
>
> <System.Diagnostics.DebuggerNonUserCode()> _
>
> Protected Overrides Sub Dispose(ByVal disposing As Boolean)
>
> If disposing AndAlso components IsNot Nothing Then
>
> components.Dispose()
>
> End If
>
> MyBase.Dispose(disposing)
>
> End Sub
>
> Friend WithEvents ComboBox1 As
> WindowsApplication1.StringWithIntegerComboBox
>
> '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.
>
> Private Sub InitializeComponent()
>
> Me.ComboBox1 = New WindowsApplication1.StringWithIntegerComboBox
>
> Me.SuspendLayout()
>
> '
>
> 'ComboBox1
>
> '
>
> Me.ComboBox1.Location = New System.Drawing.Point(136, 139)
>
> Me.ComboBox1.Name = "ComboBox1"
>
> Me.ComboBox1.Size = New System.Drawing.Size(235, 21)
>
> Me.ComboBox1.TabIndex = 0
>
> '
>
> 'Form1
>
> '
>
> Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
>
> Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
>
> Me.ClientSize = New System.Drawing.Size(572, 341)
>
> Me.Controls.Add(Me.ComboBox1)
>
> Me.Name = "Form1"
>
> Me.Text = "Form1"
>
> Me.ResumeLayout(False)
>
> End Sub
>
> End Class
>
> Public Class StringWithIntegerComboBox
>
> Inherits System.Windows.Forms.ComboBox
>
> Public Sub New()
>
> MyBase.New()
>
> Me.DataSource = myList
>
> Me.DisplayMember = "Str"
>
> Me.ValueMember = "Value"
>
> myList.Add(New StringWithInteger("One", 1))
>
> myList.Add(New StringWithInteger("Two", 2))
>
> myList.Add(New StringWithInteger("Three", 3))
>
> End Sub
>
> Public myList As List(Of StringWithInteger) = New List(Of
> StringWithInteger)
>
> End Class
>
> Public Class StringWithInteger
>
> Private mInteger As Integer
>
> Private mString As String
>
> Private mToStringDisplaysInteger As Boolean = False
>
> Public Sub New(ByVal str As String, ByVal value As Integer)
>
> mString = str
>
> mInteger = value
>
> End Sub
>
> Public Function Clone() As StringWithInteger
>
> Clone = New StringWithInteger(mString, mInteger)
>
> End Function
>
> Public Overrides Function ToString() As String
>
> If mToStringDisplaysInteger Then
>
> ToString = CStr(mInteger)
>
> Else
>
> ToString = mString
>
> End If
>
> End Function
>
> Public Property Str() As String
>
> Get
>
> Str = mString
>
> End Get
>
> Set(ByVal text As String)
>
> mString = text
>
> End Set
>
> End Property
>
> Public Property ToStringDisplaysSingle() As Boolean
>
> Get
>
> ToStringDisplaysSingle = mToStringDisplaysInteger
>
> End Get
>
> Set(ByVal displayInteger As Boolean)
>
> mToStringDisplaysInteger = displayInteger
>
> End Set
>
> End Property
>
> Public Property Value() As Integer
>
> Get
>
> Value = mInteger
>
> End Get
>
> Set(ByVal numb As Integer)
>
> mInteger = numb
>
> End Set
>
> End Property
>
> End Class
>
>


 
Reply With Quote
 
active
Guest
Posts: n/a
 
      19th Feb 2007
Sorry, I lost the New sub when I copied.
Works Ok with it.


" active" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I tried to use a datasource with a combobox and it didn't work completely
>so I build a small test that was much more straight forward then the app.
>
> The test was to see if the combobox dropdown list displayed the correct
> data.
>
> However, although the designer shows the combobox the combobox does not
> show at runtime.
>
> If you would be so kind as to cut the code below and paste it into a form
> maybe you can easily see why the combobox does not display.
>
>
>
> Thanks
>
>
>
>
>
>
>
> Public Class Form1
>
> Inherits System.Windows.Forms.Form
>
> 'Form overrides dispose to clean up the component list.
>
> <System.Diagnostics.DebuggerNonUserCode()> _
>
> Protected Overrides Sub Dispose(ByVal disposing As Boolean)
>
> If disposing AndAlso components IsNot Nothing Then
>
> components.Dispose()
>
> End If
>
> MyBase.Dispose(disposing)
>
> End Sub
>
> Friend WithEvents ComboBox1 As
> WindowsApplication1.StringWithIntegerComboBox
>
> '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.
>
> Private Sub InitializeComponent()
>
> Me.ComboBox1 = New WindowsApplication1.StringWithIntegerComboBox
>
> Me.SuspendLayout()
>
> '
>
> 'ComboBox1
>
> '
>
> Me.ComboBox1.Location = New System.Drawing.Point(136, 139)
>
> Me.ComboBox1.Name = "ComboBox1"
>
> Me.ComboBox1.Size = New System.Drawing.Size(235, 21)
>
> Me.ComboBox1.TabIndex = 0
>
> '
>
> 'Form1
>
> '
>
> Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
>
> Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
>
> Me.ClientSize = New System.Drawing.Size(572, 341)
>
> Me.Controls.Add(Me.ComboBox1)
>
> Me.Name = "Form1"
>
> Me.Text = "Form1"
>
> Me.ResumeLayout(False)
>
> End Sub
>
> End Class
>
> Public Class StringWithIntegerComboBox
>
> Inherits System.Windows.Forms.ComboBox
>
> Public Sub New()
>
> MyBase.New()
>
> Me.DataSource = myList
>
> Me.DisplayMember = "Str"
>
> Me.ValueMember = "Value"
>
> myList.Add(New StringWithInteger("One", 1))
>
> myList.Add(New StringWithInteger("Two", 2))
>
> myList.Add(New StringWithInteger("Three", 3))
>
> End Sub
>
> Public myList As List(Of StringWithInteger) = New List(Of
> StringWithInteger)
>
> End Class
>
> Public Class StringWithInteger
>
> Private mInteger As Integer
>
> Private mString As String
>
> Private mToStringDisplaysInteger As Boolean = False
>
> Public Sub New(ByVal str As String, ByVal value As Integer)
>
> mString = str
>
> mInteger = value
>
> End Sub
>
> Public Function Clone() As StringWithInteger
>
> Clone = New StringWithInteger(mString, mInteger)
>
> End Function
>
> Public Overrides Function ToString() As String
>
> If mToStringDisplaysInteger Then
>
> ToString = CStr(mInteger)
>
> Else
>
> ToString = mString
>
> End If
>
> End Function
>
> Public Property Str() As String
>
> Get
>
> Str = mString
>
> End Get
>
> Set(ByVal text As String)
>
> mString = text
>
> End Set
>
> End Property
>
> Public Property ToStringDisplaysSingle() As Boolean
>
> Get
>
> ToStringDisplaysSingle = mToStringDisplaysInteger
>
> End Get
>
> Set(ByVal displayInteger As Boolean)
>
> mToStringDisplaysInteger = displayInteger
>
> End Set
>
> End Property
>
> Public Property Value() As Integer
>
> Get
>
> Value = mInteger
>
> End Get
>
> Set(ByVal numb As Integer)
>
> mInteger = numb
>
> End Set
>
> End Property
>
> End Class
>
>



 
Reply With Quote
 
active
Guest
Posts: n/a
 
      19th Feb 2007
This test case works OK, but my app doesn't.

I'll try what you suggested on the app.

Thanks

"Lloyd Sheen" <(E-Mail Removed)> wrote in message
news:5E945DC0-8897-4C48-ACDC-(E-Mail Removed)...
> Sorry don't have access to VS but it seems that you are adding the entries
> after you bind the list to the combobox. Try it the other way or refresh
> the combobox after you add the entries. I don't think that adding will
> automatically cause the control to know there are entries. When you bound
> the list was empty.
>
> Lloyd Sheen
> " active" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I tried to use a datasource with a combobox and it didn't work completely
>>so I build a small test that was much more straight forward then the app.
>>
>> The test was to see if the combobox dropdown list displayed the correct
>> data.
>>
>> However, although the designer shows the combobox the combobox does not
>> show at runtime.
>>
>> If you would be so kind as to cut the code below and paste it into a form
>> maybe you can easily see why the combobox does not display.
>>
>>
>>
>> Thanks
>>
>>
>>
>>
>>
>>
>>
>> Public Class Form1
>>
>> Inherits System.Windows.Forms.Form
>>
>> 'Form overrides dispose to clean up the component list.
>>
>> <System.Diagnostics.DebuggerNonUserCode()> _
>>
>> Protected Overrides Sub Dispose(ByVal disposing As Boolean)
>>
>> If disposing AndAlso components IsNot Nothing Then
>>
>> components.Dispose()
>>
>> End If
>>
>> MyBase.Dispose(disposing)
>>
>> End Sub
>>
>> Friend WithEvents ComboBox1 As
>> WindowsApplication1.StringWithIntegerComboBox
>>
>> '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.
>>
>> Private Sub InitializeComponent()
>>
>> Me.ComboBox1 = New WindowsApplication1.StringWithIntegerComboBox
>>
>> Me.SuspendLayout()
>>
>> '
>>
>> 'ComboBox1
>>
>> '
>>
>> Me.ComboBox1.Location = New System.Drawing.Point(136, 139)
>>
>> Me.ComboBox1.Name = "ComboBox1"
>>
>> Me.ComboBox1.Size = New System.Drawing.Size(235, 21)
>>
>> Me.ComboBox1.TabIndex = 0
>>
>> '
>>
>> 'Form1
>>
>> '
>>
>> Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
>>
>> Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
>>
>> Me.ClientSize = New System.Drawing.Size(572, 341)
>>
>> Me.Controls.Add(Me.ComboBox1)
>>
>> Me.Name = "Form1"
>>
>> Me.Text = "Form1"
>>
>> Me.ResumeLayout(False)
>>
>> End Sub
>>
>> End Class
>>
>> Public Class StringWithIntegerComboBox
>>
>> Inherits System.Windows.Forms.ComboBox
>>
>> Public Sub New()
>>
>> MyBase.New()
>>
>> Me.DataSource = myList
>>
>> Me.DisplayMember = "Str"
>>
>> Me.ValueMember = "Value"
>>
>> myList.Add(New StringWithInteger("One", 1))
>>
>> myList.Add(New StringWithInteger("Two", 2))
>>
>> myList.Add(New StringWithInteger("Three", 3))
>>
>> End Sub
>>
>> Public myList As List(Of StringWithInteger) = New List(Of
>> StringWithInteger)
>>
>> End Class
>>
>> Public Class StringWithInteger
>>
>> Private mInteger As Integer
>>
>> Private mString As String
>>
>> Private mToStringDisplaysInteger As Boolean = False
>>
>> Public Sub New(ByVal str As String, ByVal value As Integer)
>>
>> mString = str
>>
>> mInteger = value
>>
>> End Sub
>>
>> Public Function Clone() As StringWithInteger
>>
>> Clone = New StringWithInteger(mString, mInteger)
>>
>> End Function
>>
>> Public Overrides Function ToString() As String
>>
>> If mToStringDisplaysInteger Then
>>
>> ToString = CStr(mInteger)
>>
>> Else
>>
>> ToString = mString
>>
>> End If
>>
>> End Function
>>
>> Public Property Str() As String
>>
>> Get
>>
>> Str = mString
>>
>> End Get
>>
>> Set(ByVal text As String)
>>
>> mString = text
>>
>> End Set
>>
>> End Property
>>
>> Public Property ToStringDisplaysSingle() As Boolean
>>
>> Get
>>
>> ToStringDisplaysSingle = mToStringDisplaysInteger
>>
>> End Get
>>
>> Set(ByVal displayInteger As Boolean)
>>
>> mToStringDisplaysInteger = displayInteger
>>
>> End Set
>>
>> End Property
>>
>> Public Property Value() As Integer
>>
>> Get
>>
>> Value = mInteger
>>
>> End Get
>>
>> Set(ByVal numb As Integer)
>>
>> mInteger = numb
>>
>> End Set
>>
>> End Property
>>
>> End Class
>>
>>

>



 
Reply With Quote
 
active
Guest
Posts: n/a
 
      19th Feb 2007
You got that right. If I delay Binding until after I've filled the list it
displays OK.

Refreshing the combobox didn't work.

After I've changed data in the list I need a way to "unbind" the list and
"rebind" it.

How do you think I should do that?

Thanks for the help


"Lloyd Sheen" <(E-Mail Removed)> wrote in message
news:5E945DC0-8897-4C48-ACDC-(E-Mail Removed)...
> Sorry don't have access to VS but it seems that you are adding the entries
> after you bind the list to the combobox. Try it the other way or refresh
> the combobox after you add the entries. I don't think that adding will
> automatically cause the control to know there are entries. When you bound
> the list was empty.
>
> Lloyd Sheen



 
Reply With Quote
 
Lloyd Sheen
Guest
Posts: n/a
 
      19th Feb 2007
Ok , still don't have access to code but if the refresh doesn't work then
you just need to rebind the datasource. When you bind it will refresh the
contents according to the new content. Just resetting the datasource
property should do it.

Lloyd


" active" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> You got that right. If I delay Binding until after I've filled the list it
> displays OK.
>
> Refreshing the combobox didn't work.
>
> After I've changed data in the list I need a way to "unbind" the list and
> "rebind" it.
>
> How do you think I should do that?
>
> Thanks for the help
>
>
> "Lloyd Sheen" <(E-Mail Removed)> wrote in message
> news:5E945DC0-8897-4C48-ACDC-(E-Mail Removed)...
>> Sorry don't have access to VS but it seems that you are adding the
>> entries after you bind the list to the combobox. Try it the other way or
>> refresh the combobox after you add the entries. I don't think that
>> adding will automatically cause the control to know there are entries.
>> When you bound the list was empty.
>>
>> Lloyd Sheen

>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Crystal Report Designer shows Machine Code Tony K Microsoft VB .NET 1 19th Oct 2009 01:46 PM
datagrid, change combobox value at run time based on the value of another combobox at different column zhuang Microsoft Dot NET 0 1st Mar 2006 09:31 AM
datagrid, change combobox value at run time based on the value of another combobox at different column zhuang Microsoft Dot NET Framework Forms 0 23rd Feb 2006 05:04 PM
Forms designer hangs when control added (combobox or listbox so far) no Microsoft Dot NET Framework Forms 1 4th Feb 2005 04:09 PM
PRB: Combobox inheritance and Form designer Michael Reimann Microsoft Dot NET Framework Forms 3 15th Oct 2003 11:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:20 AM.