Solved

Add Specific Text with IDs to ComboBox

Posted on 2009-05-04
8
319 Views
Last Modified: 2012-05-06
I have a tabcontrol where each tabpages tag holds an id number and the text of the tabpage holds the name of the item.
ie.
TabPage 0
Text = Heat 1
Tag = 2

Text = Heat 2
Tag = 3

I now need to take the text and tag from each tab and load into a combobox.
Being a .Net newbi and since it's not coming from a datasource, I am not sure of the best way to fill this.

Please provide an example and not a link.  Clicking on links crashes my ie.
Thanks
0
Comment
Question by:Sheritlw
  • 5
  • 3
8 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24301280
'Copy and paste this code in your form...

Private Class MyItems
Private _text as string = string.empty
Private  _ID as Integer = -1

  Public Property Text() As String
        Get
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property

 Public Property ID() As Integer
        Get
            Return _ID
        End Get
        Set(ByVal value As Integer)
            _ID = value
        End Set
    End Property

 Public Overrides Function ToString() As String
        Return _Text
    End Function

End Class


For Each ctrl As TabPage In TabControl1.TabPages

DIm MyItem as new MyItems

MyItem.text = Tabpage.Text
MyItem.Id =  ctype(Tabpage.tag,integer)

Combobox1.Item.Add(MyItem)
           
Next
0
 

Author Comment

by:Sheritlw
ID: 24301528
That works great, but since value member isn't used how do I get what item ID is selected?
Thanks
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24301622
Try this one...

If not Combobox1.SelectedItem is nothing then
   msgbox(ctype(Combobox1.SelectedItem,MyItems).ID)
End If
0
 

Author Comment

by:Sheritlw
ID: 24301695
The comboboxes are on a dialog form that I fill from the main form.  The main form has the class code you gave me before.
How would I declare myitems in the dialog form, since it won't be new?
Thanks
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 15

Accepted Solution

by:
JackOfPH earned 500 total points
ID: 24301748
Okey Here is a revision,

Create a new Class named MyItems, then copy and paste this code in the class.

Public Class MyItems
Private _text as string = string.empty
Private  _ID as Integer = -1

  Public Property Text() As String
        Get
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property

 Public Property ID() As Integer
        Get
            Return _ID
        End Get
        Set(ByVal value As Integer)
            _ID = value
        End Set
    End Property

 Public Overrides Function ToString() As String
        Return _Text
    End Function

End Class

0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24301756
Additionaly, delete this code in your main form...

Private Class MyItems
Private _text as string = string.empty
Private  _ID as Integer = -1

  Public Property Text() As String
        Get
            Return _Text
        End Get
        Set(ByVal value As String)
            _Text = value
        End Set
    End Property

 Public Property ID() As Integer
        Get
            Return _ID
        End Get
        Set(ByVal value As Integer)
            _ID = value
        End Set
    End Property

 Public Overrides Function ToString() As String
        Return _Text
    End Function

End Class
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24301780
Then After doing all these things...

You can retrieve it like this in your dialog form.

If not Combobox1.SelectedItem is nothing then
   msgbox(ctype(Combobox1.SelectedItem,MyItems).ID)
End If
0
 

Author Comment

by:Sheritlw
ID: 24301991
Thank you very much.
That works great!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now