Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add Specific Text with IDs to ComboBox

Posted on 2009-05-04
8
Medium Priority
?
332 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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
 
LVL 15

Accepted Solution

by:
JackOfPH earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

824 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