473,563 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

combobox binding question

I am forgetting something obvious, I think. I have a form with a combobox on
it. I place the code (below) in the form. Instead of populating the dropdown
with 0 and 1, as I expected, it populates it with two rows, each containing
the string "MyProject.Form 1+test"

What am I missing (besides sleep)? Do I need to implement some kind of
interface in test?

Public Class test
Public Sub New(ByVal v As Integer)
Me.Value = v
End Sub
Public Value As Integer
End Class

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim x As New ArrayList
x.Add(New test(0))
x.Add(New test(1))
cbo.DataSource = x
End Sub

-AJ
Nov 21 '05 #1
3 972
For the datasource, you can use any object that implements iList.

If you want to use an ArrayList, just populate it with strings and assign
the ComboBox.dataso urce to the ArrayList. The ComboBox.Select edIndex
property will return the zero-based index value of the entry.

You could use a DataTable, or a DataView as the datasource. You can assign
the ComboBox.Displa yMember and ValueMember properties to the corresponding
fields of the DataTable. In that case the SelectedValue property will return
the field value of ValueMember, and DisplayMember provides the list of
visible items.

www.charlesfarriersoftware.com

"Adam J. Schaff" wrote:
I am forgetting something obvious, I think. I have a form with a combobox on
it. I place the code (below) in the form. Instead of populating the dropdown
with 0 and 1, as I expected, it populates it with two rows, each containing
the string "MyProject.Form 1+test"

What am I missing (besides sleep)? Do I need to implement some kind of
interface in test?

Public Class test
Public Sub New(ByVal v As Integer)
Me.Value = v
End Sub
Public Value As Integer
End Class

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim x As New ArrayList
x.Add(New test(0))
x.Add(New test(1))
cbo.DataSource = x
End Sub

-AJ

Nov 21 '05 #2
Hi,
You can bind to an arraylist and show any property in the class.
Change you class to this.
Public Class test

Dim mVal As Integer

Public Sub New(ByVal v As Integer)

Me.Value = v

End Sub

Public Property Value() As Integer

Get

Return mVal

End Get

Set(ByVal Value As Integer)

mVal = Value

End Set

End Property

End Class

Dont forget to set the display member

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim x As New ArrayList
x.Add(New test(0))
x.Add(New test(1))
cbo.DataSource = x

cbo.displaymemb er = "Value"
End Sub

Ken
---------------------
"Adam J. Schaff" <ab****@adelphi a.net> wrote in message
news:ur******** ******@TK2MSFTN GP14.phx.gbl...
I am forgetting something obvious, I think. I have a form with a combobox on
it. I place the code (below) in the form. Instead of populating the dropdown
with 0 and 1, as I expected, it populates it with two rows, each containing
the string "MyProject.Form 1+test"

What am I missing (besides sleep)? Do I need to implement some kind of
interface in test?

Public Class test
Public Sub New(ByVal v As Integer)
Me.Value = v
End Sub
Public Value As Integer
End Class

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim x As New ArrayList
x.Add(New test(0))
x.Add(New test(1))
cbo.DataSource = x
End Sub

-AJ

Nov 21 '05 #3
Thanks! I had tried setting the DisplayMember, but I hadn't tried using
true properties instead of public variables. I had no idea there was such a
difference. Ironically, I always use full properties in my classes for
professional work. I was "cheating" here because I was working on a quick,
throwaway application to test a concept.

Anyway, thanks again for the help.

"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:ea******** ******@TK2MSFTN GP09.phx.gbl...
Hi,
You can bind to an arraylist and show any property in the class.
Change you class to this.
Public Class test

Dim mVal As Integer

Public Sub New(ByVal v As Integer)

Me.Value = v

End Sub

Public Property Value() As Integer

Get

Return mVal

End Get

Set(ByVal Value As Integer)

mVal = Value

End Set

End Property

End Class

Dont forget to set the display member

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim x As New ArrayList
x.Add(New test(0))
x.Add(New test(1))
cbo.DataSource = x

cbo.displaymemb er = "Value"
End Sub

Ken
---------------------
"Adam J. Schaff" <ab****@adelphi a.net> wrote in message
news:ur******** ******@TK2MSFTN GP14.phx.gbl...
I am forgetting something obvious, I think. I have a form with a combobox
on
it. I place the code (below) in the form. Instead of populating the
dropdown
with 0 and 1, as I expected, it populates it with two rows, each
containing
the string "MyProject.Form 1+test"

What am I missing (besides sleep)? Do I need to implement some kind of
interface in test?

Public Class test
Public Sub New(ByVal v As Integer)
Me.Value = v
End Sub
Public Value As Integer
End Class

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim x As New ArrayList
x.Add(New test(0))
x.Add(New test(1))
cbo.DataSource = x
End Sub

-AJ

Nov 21 '05 #4

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

Similar topics

1
2617
by: Bruce | last post by:
Hi, there, I meet a problem about comboBox binding. -------------------- Database: Northwind Tables: 1) Products 2) Categories I create a form (named "form1") to edit the record from Products table.
4
4605
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box bound to a table as a lookup, drawing values from another table to populate the available selections. This all worked fine in VB6. I have...
5
9152
by: Eric A. Johnson | last post by:
Hi Everyone, I am at my wit's end here. I have a combobox (combyQueryTitle) that I need to use in order to select a query for my database project. Therefore, I am using the comboQueryTitle_SelectedIndexChanged handler to, when a new selection is made, update the query and refresh the display. The only problem is that the program seems to...
3
4566
by: amber | last post by:
Hello, I have 6 comboboxes, that I thought I could bind to the same datasource, and have them display different 'selectedvalue's', but apparently I can't... My code is as follows: dim drv as datarowview = me.listbox1.selecteditem dim dtbDL as datatable = _dataset1.Tables(0) dim dtvDL as new dataview(dtbDL) dtvDL.RowFilter = "STR_ONE" =...
6
2857
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox and the coresponding 'Id' from the lookup table is to be inserted into the field of the new record. I have two simple tables. "tblPerson" is the...
2
8654
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a list of values from a table, and as the user selects values, a datagrid displays related records from another table because it is bound via FK...
5
4641
by: Joe | last post by:
Hi I am adding a class to a ComboBox - and all is fine except that I fill the combobox on the Form_Load Method and it causes the method private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) To fire twice Once when I comboBox2.DataSource = allMonths; And again when I execute comboBox2.DisplayMember = "Name";
0
2000
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number of different screens down to a minimum, I'm trying to use the same Windows Forms for both browsing and for updating. This works fine for TextBoxes,...
3
7500
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going on. It's a simple program that loads a control onto a form and binds "Foo" against a combobox ("SelectedItem") for it's "Bar" property and a...
2
1820
by: gleadams | last post by:
I have databound a Windows form ComboBox control to a DataSource and DataMember and it is properly showing the data as I navigate through the records. My question concerns the choices in the pull-down list itself. The Field is Priority and the only available choices should be "High", "Low", "Do Not Call". These are the only choices I...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7948
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.