|
-
Mar 12th, 2004, 09:16 AM
#1
Thread Starter
PowerPoster
ComboBox Multiple Fields [Resolved -Superbly]
HI,,
I need to display a Surname field and a Forenames field when the record is selected in a Combobox. I also need to have an ID field stored in the ValueMember property. I can see nothing in previous threads or MSDN Help on this. Is it so simple it does not need comment or can it not be accomplished?
Last edited by taxes; Mar 17th, 2004 at 09:21 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 12th, 2004, 09:40 AM
#2
Member
You could alway use a multicolumn combobox.
Edneeis made one that I think works great. go to www.edneeis.com
/Unisse
-
Mar 12th, 2004, 11:39 AM
#3
Thread Starter
PowerPoster
Hi unisse,
"You could alway use a multicolumn combobox.
Are you sure? I thought the multicolumn property simply used verticle columns to reduce the amount of scrolling required, not that they could show different fields.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 12th, 2004, 11:44 AM
#4
Fanatic Member
what about creating a collection of custom objects and binding that to the combobox?
-
Mar 12th, 2004, 11:56 AM
#5
Thread Starter
PowerPoster
Hi nswan,
"what about creating a collection of custom objects and binding that to the combobox?"
Fine. But how do I locate the various fields of the data row? Where are they in the combobox?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 12th, 2004, 12:25 PM
#6
Fanatic Member
i thought you wanted to bind FirstName & " " & Surname to the combo box textvalue and personID to the valuemember?
-
Mar 12th, 2004, 12:39 PM
#7
Thread Starter
PowerPoster
Hi nswan,
Yes, exactly.
I misunderstood your previous post. What you are saying is bind e.g. a textbox to the database and then bind the combobox to the textbox?
I had hoped I could retrieve the info. direct from the combobox.
Last edited by taxes; Mar 17th, 2004 at 05:46 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 14th, 2004, 06:51 PM
#8
Fanatic Member
Hi taxes,
i'm not sure if i've got the wrong end of the stick for what you want but this is what i meant anyway
Code:
Public Class person
Dim intPersonID As Integer
Dim strPersonName As String
Public Property personID() As Integer
Get
Return intPersonID
End Get
Set(ByVal Value As Integer)
intPersonID = Value
End Set
End Property
Public Property personName() As String
Get
Return strPersonName
End Get
Set(ByVal Value As String)
strPersonName = Value
End Set
End Property
End Class
'then in your form
Dim myCol As New System.Collections.ArrayList
Dim person1 As New person
person1.personName = "Andy" & " " & "Smith"
person1.personID = 1
myCol.Add(person1)
Dim person2 As New person
person2.personName = "Chris" & " " & "Jones"
person2.personID = 2
myCol.Add(person2)
cboFriends.DataSource = myCol
cboFriends.DisplayMember = "personName"
cboFriends.ValueMember = "personID"
obviously you'd set "andy" and "smith" to firstname and surname from the database, and id would be got from there as well.
Don't know if this is what you are after but if not at least it's bought the thread alive again 
cheers
Nick
-
Mar 15th, 2004, 01:08 AM
#9
Originally posted by taxes
Hi unisse,
"You could alway use a multicolumn combobox.
Are you sure? I thought the multicolumn property simply used verticle columns to reduce the amount of scrolling required, not that they could show different fields.
I don't think he meant the multicolumn property, I made an actual mutlicolumn combobox control (somewhat like the access one).
-
Mar 15th, 2004, 08:30 AM
#10
Thread Starter
PowerPoster
Hi Edneeis,
Sounds just what I need. I have downloaded and unzipped the files but can't see the .DLL. How do I put your control into my toolbox please?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 16th, 2004, 12:07 AM
#11
It's there under \Control\bin\Edneeis.Controls.MultiColumnCombo.dll and to add it to the toolbox you just right click on the toolbox and click 'Add/Remove items' then browse to the dll.
-
Mar 16th, 2004, 03:41 PM
#12
Thread Starter
PowerPoster
Hi Edneeis,
Many thanks. It definitely has possibilities. It does not suit my present problem, however. How can I access the other fields in the record of the selection shown in a ComboBox.Display property? I would like to show them in a textbox or label.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 16th, 2004, 08:34 PM
#13
Thread Starter
PowerPoster
Hi Nick,
"obviously you'd set "andy" and "smith" to firstname and surname from the database, and id would be got from there as well. "
I like the look of what you suggest, but I'm afraid I can't figure out how to get the data from the database (Access) into the arraylist. I've tried messing around with a DataAdapter and a DataSet with no success. Any ideas please?
Also, would it be possible to load the data from the database into a multidimension array, i.e. each element representing a row and each dimension containing one column?
Many thanks.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 16th, 2004, 11:46 PM
#14
Originally posted by taxes
Hi Edneeis,
Many thanks. It definitely has possibilities. It does not suit my present problem, however. How can I access the other fields in the record of the selection shown in a ComboBox.Display property? I would like to show them in a textbox or label.
You would use databinding and bind to the same source as the combo. Although on a re-read it doesn't seem that you really are wanting a multicolumn thing for a combo but just want to access the selected item from the combo. You can use binding as I mentioned or simply use the SelectedItem object to reach the selected item. Its a matter of what are you actually storing in your combo? A string? An object? A dataset?
-
Mar 17th, 2004, 05:04 AM
#15
Thread Starter
PowerPoster
Hi Edneeis,
"Its a matter of what are you actually storing in your combo? A string? An object? A dataset?"
I am using a Dataset, but I want to display, either in the ComboBox or in a textbox, two other fields - as well as leaving the ID field in the combo valuemember. Perhaps this is just not possible and I will have to take another route, but the combo is so convenient.
I am looking at nswan's suggestion, but I cannot see how to populate the ArrayList from the dataset.
Many thanks.
Last edited by taxes; Mar 17th, 2004 at 05:47 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 17th, 2004, 05:06 AM
#16
Fanatic Member
give me an hour or so and i'll have some code for you
Nick
-
Mar 17th, 2004, 07:09 AM
#17
Fanatic Member
ok here you go
Code:
Imports System.Data.OleDb
Dim blnFinishedLoading As Boolean = False
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConnection As String = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=c:\friends.mdb"
Dim myConnection As New OleDbConnection(strConnection)
Dim daFriends As New OleDbDataAdapter("select * from tblFriend", myConnection)
Dim dsFriends As New DataSet()
Try
daFriends.Fill(dsFriends, "friends")
Dim intCount As Integer
Dim friendsArray As New System.Collections.ArrayList()
For intCount = 0 To dsFriends.Tables("friends").Rows.Count - 1
Dim newFriend As New person()
Dim strName As String
newFriend.personID = dsFriends.Tables("friends").Rows(intCount).Item("ID")
strName = dsFriends.Tables("friends").Rows(intCount).Item("Firstname") & _
" " & _
dsFriends.Tables("friends").Rows(intCount).Item("Surname")
newFriend.personName = strName
friendsArray.Add(newFriend)
Next
cboFriend.DisplayMember = "personName"
cboFriend.ValueMember = "personID"
cboFriend.DataSource = friendsArray
blnFinishedLoading = True
Catch ex As OleDbException
MsgBox(ex.ToString)
End Try
End Sub
Private Sub cboFriend_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboFriend.SelectedIndexChanged
If blnFinishedLoading Then
TextBox1.Text = cboFriend.Text
TextBox2.Text = cboFriend.SelectedValue
End If
End Sub
'THE ACTUAL CLASS#######################
Public Class person
Dim intPersonID As Integer
Dim strPersonName As String
Public Property personID() As Integer
Get
Return intPersonID
End Get
Set(ByVal Value As Integer)
intPersonID = Value
End Set
End Property
Public Property personName() As String
Get
Return strPersonName
End Get
Set(ByVal Value As String)
strPersonName = Value
End Set
End Property
End Class
The reason for blnFinishedLoading is that when you bind to a combobox the selectedindexchanged event seems to fire for each item you add. Obviously you don't want that to happen until the user actually clicks on the combo box!
Hope this helps
Nick
-
Mar 17th, 2004, 09:19 AM
#18
Thread Starter
PowerPoster
Hi Nick
Brilliant! Many thanks. When I used your code I changed some of the variable and property names to suit my actual application (it handles tennis player's rankings) so I'm not absolutely sure but should you have included
I have had a look at your site and I can hardly believe what you are freely offering. Congratulations. I have a proposition you may be interested in and will phone you within 2 weeks when I have researched it a little further.
Once again, many thanks.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Mar 17th, 2004, 09:40 AM
#19
Fanatic Member
glad to have been of help and look forward to hearing from you.
Nick
-
Jul 17th, 2012, 01:48 AM
#20
New Member
Re: ComboBox Multiple Fields [Resolved -Superbly]
can edneeis or someone please up load file Edneeis.Controls.MultiColumnCombo.dll for me? i can't download it anywhere
-
Jul 18th, 2012, 08:16 AM
#21
Thread Starter
PowerPoster
Re: ComboBox Multiple Fields [Resolved -Superbly]
 Originally Posted by bobochacha29
can edneeis or someone please up load file Edneeis.Controls.MultiColumnCombo.dll for me? i can't download it anywhere
Hi,
I thought this one was long dead!
Look at posts 10 & 11 above
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|