Solved

Add Specific Text with IDs to ComboBox

Posted on 2009-05-04
8
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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!

 

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

Industry Leaders: 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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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