I used the following two routines to fil a drop-down box in a VS 2003 web
project
What do I need to do to make these work with list controls in 2005 Windows
Projects?

========================================

Private Sub FillWithDepts(ByVal strStartDate As String)

Dim drDepts As SqlClient.SqlDataReader
drDepts = AppointmentsBLL.GetDeptNames(strStartDate)
Me.cmbSourceList.Items.Clear()
Me.cmbSourceList.Items.Add(New ListItem("", ""))
Do While drDepts.Read
Me.cmbSourceList.Items.Add(New ListItem(drDepts("Dept")))
Loop


End Sub



Public Shared Function GetDeptNames(ByVal strStartDate As String) As
SqlDataReader
'This function gets the Dept names from the most recent appointment
table
'with related date
'functions as a data reader
Dim drDepts As SqlDataReader
Dim conMembers As SqlConnection = GetMembershipConnection()
Dim strSQL As String

strSQL = "SELECT DISTINCT Dept " _
& "FROM tbl_Appt WHERE ApptDate =@StartDate Order by Dept "

Dim cmdGetDepts As New SqlCommand(strSQL, conMembers)
cmdGetDepts.CommandType = CommandType.Text

Dim pStartDt As New SqlParameter("@StartDate", SqlDbType.VarChar)
With cmdGetDepts
pStartDt.Direction = ParameterDirection.Input
pStartDt.Value = strStartDate
.Parameters.Add(pStartDt)
End With



conMembers.Open()
drDepts = cmdGetDepts.ExecuteReader(CommandBehavior.CloseConnection)
Return drDepts

End Function

Re: Filling a combobox in 2005 by Otis

Otis
Fri Aug 18 21:21:44 CDT 2006

On Fri, 18 Aug 2006 17:17:01 -0700, jonefer <jonefer@discussions.microsoft.com>
wrote:

>I used the following two routines to fil a drop-down box in a VS 2003 web
>project
>What do I need to do to make these work with list controls in 2005 Windows
>Projects?
>
>========================================
>
>Private Sub FillWithDepts(ByVal strStartDate As String)
>
> Dim drDepts As SqlClient.SqlDataReader
> drDepts = AppointmentsBLL.GetDeptNames(strStartDate)
> Me.cmbSourceList.Items.Clear()
> Me.cmbSourceList.Items.Add(New ListItem("", ""))
> Do While drDepts.Read
> Me.cmbSourceList.Items.Add(New ListItem(drDepts("Dept")))
> Loop
>
>
> End Sub
>
>
>
>Public Shared Function GetDeptNames(ByVal strStartDate As String) As
>SqlDataReader
> 'This function gets the Dept names from the most recent appointment
>table
> 'with related date
> 'functions as a data reader
> Dim drDepts As SqlDataReader
> Dim conMembers As SqlConnection = GetMembershipConnection()
> Dim strSQL As String
>
> strSQL = "SELECT DISTINCT Dept " _
> & "FROM tbl_Appt WHERE ApptDate =@StartDate Order by Dept "
>
> Dim cmdGetDepts As New SqlCommand(strSQL, conMembers)
> cmdGetDepts.CommandType = CommandType.Text
>
> Dim pStartDt As New SqlParameter("@StartDate", SqlDbType.VarChar)
> With cmdGetDepts
> pStartDt.Direction = ParameterDirection.Input
> pStartDt.Value = strStartDate
> .Parameters.Add(pStartDt)
> End With
>
>
>
> conMembers.Open()
> drDepts = cmdGetDepts.ExecuteReader(CommandBehavior.CloseConnection)
> Return drDepts
>
> End Function

Instead of returning a DataReader from your function, return a List or DataSet
then bind it to the combobox using the comboboxes dataSource property.

search for ComboBox.DataSource in the help files. Simple programming practice;
first look in the help files and search Google.
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com

Re: Filling a combobox in 2005 by jonefer

jonefer
Sat Aug 19 18:39:01 CDT 2006

That's why I wrote in this newsgroup, I tried what you said first - and it
didn't work.
Almost every demo I find in google shows how to use the graphical tools to
bind to the new combobox, but I want to be able to several different
resultsets to the combobox based on different criteria, so the graphical tool
doesn't help.

I prefer not to use a tableAdapter, but if I can,

I know it isn't as simple as

MyComboBox.DataSource = dtMyDataTable

or is it?

"Otis Mukinfus" wrote:

> On Fri, 18 Aug 2006 17:17:01 -0700, jonefer <jonefer@discussions.microsoft.com>
> wrote:
>
> >I used the following two routines to fil a drop-down box in a VS 2003 web
> >project
> >What do I need to do to make these work with list controls in 2005 Windows
> >Projects?
> >
> >========================================
> >
> >Private Sub FillWithDepts(ByVal strStartDate As String)
> >
> > Dim drDepts As SqlClient.SqlDataReader
> > drDepts = AppointmentsBLL.GetDeptNames(strStartDate)
> > Me.cmbSourceList.Items.Clear()
> > Me.cmbSourceList.Items.Add(New ListItem("", ""))
> > Do While drDepts.Read
> > Me.cmbSourceList.Items.Add(New ListItem(drDepts("Dept")))
> > Loop
> >
> >
> > End Sub
> >
> >
> >
> >Public Shared Function GetDeptNames(ByVal strStartDate As String) As
> >SqlDataReader
> > 'This function gets the Dept names from the most recent appointment
> >table
> > 'with related date
> > 'functions as a data reader
> > Dim drDepts As SqlDataReader
> > Dim conMembers As SqlConnection = GetMembershipConnection()
> > Dim strSQL As String
> >
> > strSQL = "SELECT DISTINCT Dept " _
> > & "FROM tbl_Appt WHERE ApptDate =@StartDate Order by Dept "
> >
> > Dim cmdGetDepts As New SqlCommand(strSQL, conMembers)
> > cmdGetDepts.CommandType = CommandType.Text
> >
> > Dim pStartDt As New SqlParameter("@StartDate", SqlDbType.VarChar)
> > With cmdGetDepts
> > pStartDt.Direction = ParameterDirection.Input
> > pStartDt.Value = strStartDate
> > .Parameters.Add(pStartDt)
> > End With
> >
> >
> >
> > conMembers.Open()
> > drDepts = cmdGetDepts.ExecuteReader(CommandBehavior.CloseConnection)
> > Return drDepts
> >
> > End Function
>
> Instead of returning a DataReader from your function, return a List or DataSet
> then bind it to the combobox using the comboboxes dataSource property.
>
> search for ComboBox.DataSource in the help files. Simple programming practice;
> first look in the help files and search Google.
> Good luck with your project,
>
> Otis Mukinfus
> http://www.arltex.com
> http://www.tomchilders.com
>

Re: Filling a combobox in 2005 by Klaas

Klaas
Sun Aug 20 14:12:11 CDT 2006

Yes, it is that simple.
Also provide the MyComboBox.datamemeber and value and you are good to go.


"jonefer" <jonefer@discussions.microsoft.com> schreef in bericht
news:9EEEA0C8-BAD4-42BA-9089-7CC440C24ED0@microsoft.com...
> That's why I wrote in this newsgroup, I tried what you said first - and it
> didn't work.
> Almost every demo I find in google shows how to use the graphical tools to
> bind to the new combobox, but I want to be able to several different
> resultsets to the combobox based on different criteria, so the graphical
> tool
> doesn't help.
>
> I prefer not to use a tableAdapter, but if I can,
>
> I know it isn't as simple as
>
> MyComboBox.DataSource = dtMyDataTable
>
> or is it?
>
> "Otis Mukinfus" wrote:
>
>> On Fri, 18 Aug 2006 17:17:01 -0700, jonefer
>> <jonefer@discussions.microsoft.com>
>> wrote:
>>
>> >I used the following two routines to fil a drop-down box in a VS 2003
>> >web
>> >project
>> >What do I need to do to make these work with list controls in 2005
>> >Windows
>> >Projects?
>> >
>> >========================================
>> >
>> >Private Sub FillWithDepts(ByVal strStartDate As String)
>> >
>> > Dim drDepts As SqlClient.SqlDataReader
>> > drDepts = AppointmentsBLL.GetDeptNames(strStartDate)
>> > Me.cmbSourceList.Items.Clear()
>> > Me.cmbSourceList.Items.Add(New ListItem("", ""))
>> > Do While drDepts.Read
>> > Me.cmbSourceList.Items.Add(New ListItem(drDepts("Dept")))
>> > Loop
>> >
>> >
>> > End Sub
>> >
>> >
>> >
>> >Public Shared Function GetDeptNames(ByVal strStartDate As String) As
>> >SqlDataReader
>> > 'This function gets the Dept names from the most recent
>> > appointment
>> >table
>> > 'with related date
>> > 'functions as a data reader
>> > Dim drDepts As SqlDataReader
>> > Dim conMembers As SqlConnection = GetMembershipConnection()
>> > Dim strSQL As String
>> >
>> > strSQL = "SELECT DISTINCT Dept " _
>> > & "FROM tbl_Appt WHERE ApptDate =@StartDate Order by Dept "
>> >
>> > Dim cmdGetDepts As New SqlCommand(strSQL, conMembers)
>> > cmdGetDepts.CommandType = CommandType.Text
>> >
>> > Dim pStartDt As New SqlParameter("@StartDate",
>> > SqlDbType.VarChar)
>> > With cmdGetDepts
>> > pStartDt.Direction = ParameterDirection.Input
>> > pStartDt.Value = strStartDate
>> > .Parameters.Add(pStartDt)
>> > End With
>> >
>> >
>> >
>> > conMembers.Open()
>> > drDepts =
>> > cmdGetDepts.ExecuteReader(CommandBehavior.CloseConnection)
>> > Return drDepts
>> >
>> > End Function
>>
>> Instead of returning a DataReader from your function, return a List or
>> DataSet
>> then bind it to the combobox using the comboboxes dataSource property.
>>
>> search for ComboBox.DataSource in the help files. Simple programming
>> practice;
>> first look in the help files and search Google.
>> Good luck with your project,
>>
>> Otis Mukinfus
>> http://www.arltex.com
>> http://www.tomchilders.com
>>