Combobox

M

Muhammad Bilal

Hi
How items can be added in a combobox at run time using values from a table.
But I want to do it only through code i.e making own connection string,
binding, datasource, displaymember etc.
 
M

Mr. Arnold

Muhammad Bilal said:
Hi
How items can be added in a combobox at run time using values from a
table.
But I want to do it only through code i.e making own connection string,
binding, datasource, displaymember etc.

You use a Dataset or a Datatable that you have populated from the table. You
can do it with a class that returns the Dataset or Datatable. The connection
information would be in the class.


cbx.Datasource = GetData()
cbx.displaymember = "table field1"
cbx.membervaluse = "table field9"


public class Getdata as Datatable

create dataset
create table in dataset
populate table in dataset
create datatable
datatable = dataset

return datatable

end class

I can't recall it off the top of my head, but I think you get the picture.
 
M

Muhammad Bilal

Hi.
I am a beginner can u give a detailed overview or recomend any site which
can be really helpful for me,

Regards
 
M

Mr. Arnold

Muhammad Bilal said:
Hi.
I am a beginner can u give a detailed overview or recomend any site which
can be really helpful for me,

<http://www.google.com/search?hl=en&...atable+to+a+control+VB.net&btnG=Google+Search>

Goggle is your friend. There are many examples in the Google link, but I
like to instantiate a class like GetData(), let GetData do the SQL
connection, get the data, make the Getdata() as a type, and bind the class
type to the control

Public class Getdata() as DataTable

all your connection and data reading for the database table
return Datatable

end class


cbx.datasource = GetData();

You can also find many code examples at DEVX and Code Project sites, use
Google to look them up.

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top