Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem binding combobox to dataset

Poonam
Guest
 
Posts: n/a
#1: Nov 21 '05
I have a department table with DeptID and DeptName. I am trying to fill
my combobox with DeptName.

Here is my code but it does not work? Can someone help me?

Dim pxy As New Channel1.Channel
dsDepts = pxy.getDepartments()
cmbDept.DisplayMember = "DeptName"
cmbDept.ValueMember = "DeptID"
cmbDept.DataSource = dsDepts.Tables("Department")

This does not give any error but it does not fill my combobox. It
remains empty.

if I give the following:
cmbDept.Datasource = dsdepts

it fills the combobox with the following:
System.Data.DataViewManagerListItemTypeDescriptor

Also do I have to add the databindings property or not?

getdepartments webmethod simply returns the dataset.

the following does not work.
cmbDept.DataSource = dsDepts.Tables(0)


It's urgent. I need help.
Poonam


Kevin Hodgson
Guest
 
Posts: n/a
#2: Nov 21 '05

re: Problem binding combobox to dataset


Here is the code I use to do something similar. You need to bind both the
DisplayMember and ValueMember to one column, and I use the Tag property to
store my ID Field.

Try something like this.
cmbDept.DataBindings.Add(New System.Windows.Forms.Binding("Tag", dsDepts,
"tablename.DeptID"))cmbDept.DataSource =DsDepts
cmbDept.DisplayMember = "tablename.DeptName"
cmbDept.ValueMember = "tablename.DeptName"

"Poonam" <poonam.g.buch@gmail.com> wrote in message
news:1109278000.034249.230790@o13g2000cwo.googlegr oups.com...[color=blue]
> I have a department table with DeptID and DeptName. I am trying to fill
> my combobox with DeptName.
>
> Here is my code but it does not work? Can someone help me?
>
> Dim pxy As New Channel1.Channel
> dsDepts = pxy.getDepartments()
> cmbDept.DisplayMember = "DeptName"
> cmbDept.ValueMember = "DeptID"
> cmbDept.DataSource = dsDepts.Tables("Department")
>
> This does not give any error but it does not fill my combobox. It
> remains empty.
>
> if I give the following:
> cmbDept.Datasource = dsdepts
>
> it fills the combobox with the following:
> System.Data.DataViewManagerListItemTypeDescriptor
>
> Also do I have to add the databindings property or not?
>
> getdepartments webmethod simply returns the dataset.
>
> the following does not work.
> cmbDept.DataSource = dsDepts.Tables(0)
>
>
> It's urgent. I need help.
> Poonam
>[/color]


Brian Swanson
Guest
 
Posts: n/a
#3: Nov 21 '05

re: Problem binding combobox to dataset


You have to run the cmbDept.Refresh after assigning the DisplayMember,
ValueMember and DataSource.

Hope this helps,
Brian Swanson

"Poonam" <poonam.g.buch@gmail.com> wrote in message
news:poonam.g.buch@gmail.com:[color=blue]
> Dim pxy As New Channel1.Channel
> dsDepts = pxy.getDepartments()
> cmbDept.DisplayMember = "DeptName"
> cmbDept.ValueMember = "DeptID"
> cmbDept.DataSource = dsDepts.Tables("Department")
>
> This does not give any error but it does not fill my combobox. It
> remains empty.[/color]

Poonam
Guest
 
Posts: n/a
#4: Nov 21 '05

re: Problem binding combobox to dataset


cmbDept.DisplayMember = "Department.DeptName"
cmbDept.ValueMember = "Department.DeptName"
cmbDept.DataSource = dsDepts
cmbDept.DataBindings.Add(New System.Windows.Forms.Binding("Tag",
dsDepts, "Department.DeptID"))


An unhandled exception of type 'System.ArgumentException' occurred in
system.windows.forms.dll

Additional information: Cannot create a child list for field
Department.

It does not work. I do not understand what the problem is.

But thanks Kevin.

Poonam

Raj Prakash
Guest
 
Posts: n/a
#5: Nov 21 '05

re: Problem binding combobox to dataset


Did you fill the dataset?
DataAdapterObject.Fill(DataSetObject)

Hope this helps...
Raj Prakash


"Poonam" <poonam.g.buch@gmail.com> wrote in message
news:1109278000.034249.230790@o13g2000cwo.googlegr oups.com...[color=blue]
>I have a department table with DeptID and DeptName. I am trying to fill
> my combobox with DeptName.
>
> Here is my code but it does not work? Can someone help me?
>
> Dim pxy As New Channel1.Channel
> dsDepts = pxy.getDepartments()
> cmbDept.DisplayMember = "DeptName"
> cmbDept.ValueMember = "DeptID"
> cmbDept.DataSource = dsDepts.Tables("Department")
>
> This does not give any error but it does not fill my combobox. It
> remains empty.
>
> if I give the following:
> cmbDept.Datasource = dsdepts
>
> it fills the combobox with the following:
> System.Data.DataViewManagerListItemTypeDescriptor
>
> Also do I have to add the databindings property or not?
>
> getdepartments webmethod simply returns the dataset.
>
> the following does not work.
> cmbDept.DataSource = dsDepts.Tables(0)
>
>
> It's urgent. I need help.
> Poonam
>[/color]


Poonam
Guest
 
Posts: n/a
#6: Nov 21 '05

re: Problem binding combobox to dataset


I did that. But still not getting there. I get errors in the display
member and value member properties.
Thanks,
Poonam


Dim pxy As New Channel1.Channel
dsDepts = pxy.getDepartments()
cmbDept.DisplayMember = "DeptName"
cmbDept.ValueMember = "DeptID"
cmbDept.DataSource = dsDepts.Tables("Department")



getDepartments webmethod is as follows:

<WebMethod()> _
Public Function getDepartments() As DataSet
Dim Sql1 As String = "Select * from Department"
Dim ds As DataSet = objDb.getdataset(Sql1)
Return ds
End Function



Public Function getDataSet(ByVal SqlSelect As String) As DataSet
Dim myDataAdapter As New OleDbDataAdapter(SqlSelect,
myConnection)
Dim myDataSet As New DataSet
myDataAdapter.Fill(myDataSet)
ds = myDataSet
Return myDataSet
End Function

Closed Thread