Results 1 to 21 of 21

Thread: ComboBox Multiple Fields [Resolved -Superbly]

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    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.

  2. #2
    Member
    Join Date
    Mar 2004
    Posts
    39
    You could alway use a multicolumn combobox.

    Edneeis made one that I think works great. go to www.edneeis.com

    /Unisse

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    what about creating a collection of custom objects and binding that to the combobox?
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  6. #6
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    i thought you wanted to bind FirstName & " " & Surname to the combo box textvalue and personID to the valuemember?
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  8. #8
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    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
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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).

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  14. #14
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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?

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  16. #16
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    give me an hour or so and i'll have some code for you

    Nick
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  17. #17
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    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
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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

    VB Code:
    1. strConnection.open

    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.

  19. #19
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    glad to have been of help and look forward to hearing from you.

    Nick
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  20. #20
    New Member
    Join Date
    Jul 2012
    Posts
    1

    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

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: ComboBox Multiple Fields [Resolved -Superbly]

    Quote Originally Posted by bobochacha29 View Post
    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
  •  



Click Here to Expand Forum to Full Width