Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank
View Poll Results: How do you feel about this program?
Very good 0 0%
Good 0 0%
Average 0 0%
Voters: 0. You may not vote on this poll


Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 1st, 2004, 09:12 AM
benoyraj benoyraj is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: US
Posts: 15 benoyraj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up Data binding to a combo box in .NET or array management with Combo box

hi,

Here, I am going to explain how to bind array variables or database tables to a combobox in .NET application.

1. Array to combo box
=================

The following line of codes will return the values from an array to combo box.

~~~~~~~~
dim Days() as String = {"SUN","MON0","TUE","WED","THU","FRI","SAT"}

combobox1.DataSource=Days
~~~~~~

2. Array List to combo box
====================

The following line of codes will return the values from an arraylist to combo box

~~~~~~~~~
dim Months as new ArrayList

'add month structure entries to the arraylist

with Months
.Add("JANUARY")
.Add("FEBRUARY")
.Add("MARCH")
.Add("APRIL")
.Add("MAY")
.Add("JUNE")
.Add("JULY")
.Add("AUGUST")
.Add("SEPTEMBER")
.Add("OCTOBER")
.Add("NOVEMBER")
.Add("DECEMBER")
End With

combobox1.DataSource=Days
~~~~~~~~~~

3. Taking key value from combo box using an arraylist
========================================

The following line of codes will return the key value from an arraylist to combo box

~~~~~~~~~

'define a structure for Year which has
' a year and id.

protected structure Months
private MonthName as String
private MonthId as Integer

public sub new(monname as String, monid as Integer)
divName=monname
divId = monid
End Sub

public readonly property getMonName() as String
get
return MonthName
End Get
end property

public readonly property getMonId() as Integer
get
return MonthID
End Get
End Property
End structure

dim MyMonths as new ArrayList

'add month structure entries to the arraylist
with MyMonths
.Add(new Years("JANUARY",1))
.Add(new Years("FEBRUARY",2))
.Add(new Years("MARCH",3))
.Add(new Years("APRIL",4))
.Add(new Years("MAY",5))
.Add(new Years("JUNE",6))
.Add(new Years("JULY",7))
.Add(new Years("AUGUST",8))
.Add(new Years("SEPTEMBER",9))
.Add(new Years("OCTOBER",10))
.Add(new Years("NOVEMBER",11))
.Add(new Years("DECEMBER",12))
End With

'bind the arraylist to the combo box
With combobox1
.datasource=MyMonths
.Displaymember="getMonName"
.ValueMember="getMonId"
End With
~~~~~~~~~~



3. Taking key value from combo box using an database
========================================

The following line of codes will return the key value from a database table to combo box

~~~~~~~~~

'bind the arraylist to the combo box
With combobox1
.Datasource=dsproducts.Tables("MONTHS")
.Displaymember="MonthName"
.ValueMember="MonthID"
End With

~~~~~~~~

PS : Similarly you can populated into combo using dataView (Protected dvMonths as DataView)


thanks

Benoy
binoy_rb@hotmail.com

Reply With Quote
  #2  
Old April 1st, 2004, 09:50 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 58 m 22 sec
Reputation Power: 469
Actually, .NET has built in ways to get the days and months, both names and values.
So, although you code seems correct (I haven't tried it), there is an easier way to do it.

Reply With Quote
  #3  
Old July 26th, 2004, 10:11 AM
karthiktp karthiktp is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 karthiktp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hai,

This question is related to VB .NET. I have a form that gets/stores customer address. I am getting data from dataset and write into in. I created a structure for US states

Public Structure State
Private shortName As String
Private longName As String
Public Sub New(ByVal lname As String, ByVal sname As String)
shortName = sname
longName = lname
End Sub
Public Property getShortName() As String
Get
Return shortName
End Get
Set(ByVal Value As String)

End Set
End Property
Public Property getLongName() As String
Get
Return longName
End Get
Set(ByVal Value As String)

End Set
End Property

End Structure

' US states array
Public USstates As State() = New State() { _
New State("Alabama", "AL") _
, New State("Alaska", "AK") _
, New State("Arizona", "AZ") _
, New State("Arkansas", "AR") _
, New State("California", "CA"),
etc
}

How do I bind the US states array to the Combo box and to the customerAddress table? The combo box should display long names such as "Arizona", etc. When user selects "Arizona", the short form "AZ" should get saved into the customer table. How could I bind it?

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Data binding to a combo box in .NET or array management with Combo box


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT