Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2006, 03:38 AM
Authorized User
 
Join Date: Nov 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Alternative for ItemData in Visual Studio 2005

Hi All,

               I m using Visual Studio 2005 and my language is VB.NET. I need to fill a combo box with the name of countries. I want to display the name of the country within the combo. and i also want to keep the code of the country with each name item.

Now i am aware that with visual basic 6.0. There is an option available for combo box named ITEMDATA. So that i can put an integer value with each item. But i can see this attributes has been terminated in VS.NET 2005.

but i am not aware that if any altervative has been provided in Visual studio.NET or if i want to do the same thing in VS.NET 2005. how i can do it. any help will be highly appreciated.

                       Tayyab.
__________________
Tiyyob
 
Old June 7th, 2006, 07:22 AM
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Tayyab

Well if u want to bind your combobox with countryname which is a string and some Integer that is code of country.
You can do it with
some class like this


Option Strict On
Option Explicit On

Public Class clsListItem
    Private mValue As String ' Stores a named description of the item
    Private mID As Long ' Stores a primary key to the record

    Public Sub New(ByVal strValue As String, ByVal intID As Long, Optional ByVal intVal As Long = 0)
        mValue = strValue
        mID = intID

    End Sub

    Public Sub New()
        mValue = ""
        mID = 0
           End Sub

    Property ID() As Long
        Get
            Return mID
        End Get
        Set(ByVal Value As Long)
            mID = Value
        End Set
    End Property

    Property Value() As String
        Get
            Return mValue
        End Get
        Set(ByVal Value As String)
            mValue = Value
        End Set
    End Property


    Public Overrides Function ToString() As String
        Return mValue
    End Function
End Class

U can fill
your combo box one by one
like this

 comboname.Items.Add(New clsListItem(NameofCountry, countrycode))


while getting the value



 countrycode= comboname.SelectedItem.id

countryname=comboname.SelectedItem.value

Gullu


gullu
 
Old June 7th, 2006, 08:19 AM
Authorized User
 
Join Date: Nov 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My Friend,

         I am truly thankful for your time. you info is helpful. this will add the object to combo box.

But I want the way that when i will add the object to the comobo box. Country name should be displayed in combo box.

but by your suggested way. when i open the combo box. It shows the name of the object Instead of its property. But i want to have the property of object(which is name in this case) must be shown.

i hope you got my point...

                         thankful

                         Tayyab
 
Old June 7th, 2006, 10:19 PM
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello

I didn't Get ur problem
where are u facing the problem
while showing the country name in country or while getting the country name from combobox

u can get the name of countryname from combo box like this

countryName=comboname.text

while country code like this
countrycode=comboname.selecteditem.id



gullu
 
Old June 8th, 2006, 10:19 PM
Authorized User
 
Join Date: Feb 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If the data source for the combobox is not normally being used to populate objects (as is often the case), you can use the following temporary object scheme for either listboxes or comboboxes:

    Friend Class ListBoxItem
        Private m_Text As String
        Private m_ItemData As Integer
        Public Sub New(ByVal ThisText As String, ByVal ThisItemData As Integer)
            m_Text = ThisText
            m_ItemData = ThisItemData
        End Sub
        Public Overrides Function ToString() As String
            Return m_Text
        End Function
        Public ReadOnly Property ItemData() As Integer
            Get
                Return m_ItemData
            End Get
        End Property
    End Class

Then add a new combobox item as follows:
YourCombobox.Items.Add(New ListBoxItem(sometext, someint))

and retrieve the ItemData later:
ThisItemData = CType(YourCombobox.Items(index, ListBoxItem).ItemData





Similar Threads
Thread Thread Starter Forum Replies Last Post
Can i use visual studio 2005 !! swapnil_sandy ASP.NET 2.0 Basics 2 November 2nd, 2006 12:40 AM
FTP in Visual Studio 2005 Pro (Visual Basic) shoopes VB How-To 1 June 29th, 2006 02:08 PM
Visual Studio 2005 ermutigen BOOK: Professional Crystal Reports for VS.NET 1 June 27th, 2006 02:44 PM
Visual Studio 2003 vs. Visual Studio 2005 eitanbarazani C# 2005 4 May 9th, 2006 01:34 AM
Visual Studio .net2003 and Visual Studio 2005 Gert Visual C++ 1 January 24th, 2006 05:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.