473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Filling up a combobox

dear,

I have a form (frmlogonaccounts.cs) with a combobox, which I want to fill up
with the first column of a dataset. The dataset is created in the class
Login. My problem is the next : I make a new login in the form loginaccount
which create a new login and give me a dataset (created by class login),
which I can see in my datagrid. But I want to fill up my combobox with only
the name of the logon and I do this with an foreach. But when I see the
result the combobox is filled up with only the name of the column, not with
the data in the dataset (as I said I see the data in the datagrid: so the
dataset is filled up).

What do I wrong ? Below you find the code in class Login and class
frmlogonaccount

Thank you very much.

Hugo

code Login :

public Login(out DataSet ds)
{
SqlSelectie = "select * from Login; ";
Database db = new Database();
SqlConnection conn = db.Opent();
SqlCommand cmd = new SqlCommand(SqlSelectie, conn);
SqlDataAdapter da = new SqlDataAdapter(SqlSelectie, conn);
ds = new DataSet();
da.Fill(ds, "Login");
conn.Close();
}

code frmlogonaccount :

DataSet ds = new DataSet("Login");
Login SqlLogin = new Login(out ds);
dataGrid1.SetDataBinding(ds, "Login");
///the next statement gives me the name of the column NOT the data
foreach (DataRow dr in ds.Tables["Login"].Rows)
cboListLogon.Items.Add(dr.Table.Columns[0]);
Nov 15 '05 #1
2 3448
Hi Hugo,

"Hugo Lefevre" <hu**********@tiscali.be> wrote in message
news:bu**********@news.worldonline.be...
dear,

I have a form (frmlogonaccounts.cs) with a combobox, which I want to fill up with the first column of a dataset. The dataset is created in the class
Login. My problem is the next : I make a new login in the form loginaccount which create a new login and give me a dataset (created by class login),
which I can see in my datagrid. But I want to fill up my combobox with only the name of the logon and I do this with an foreach. But when I see the
result the combobox is filled up with only the name of the column, not with the data in the dataset (as I said I see the data in the datagrid: so the
dataset is filled up).

What do I wrong ? Below you find the code in class Login and class
frmlogonaccount

Thank you very much.

Hugo

code Login :

public Login(out DataSet ds)
{
SqlSelectie = "select * from Login; ";
Database db = new Database();
SqlConnection conn = db.Opent();
SqlCommand cmd = new SqlCommand(SqlSelectie, conn);
SqlDataAdapter da = new SqlDataAdapter(SqlSelectie, conn);
ds = new DataSet();
da.Fill(ds, "Login");
conn.Close();
}

code frmlogonaccount :

DataSet ds = new DataSet("Login");
Login SqlLogin = new Login(out ds);
dataGrid1.SetDataBinding(ds, "Login");
///the next statement gives me the name of the column NOT the data
foreach (DataRow dr in ds.Tables["Login"].Rows)
cboListLogon.Items.Add(dr.Table.Columns[0]);


It should be:
cboListLogon.Items.Add((string)dr[0]);
instead.
Also you might consider databinding to combobox entire table
ds.Tables["Login"].
Just set DisplayMember = "columnname" and DataSource = ds.Tables["Login"];

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com
Nov 15 '05 #2
Hi Hugo,

You can try databinding the login name column to your
combobox by using the DisplayMember and ValueMember
properties. Here's a code snippet:

cboListLogon.DataSource=ds.Tables["Login"];
cboListLogon.DisplayMember="loginname";
cboListLogon.ValueMember="loginname";

Regards,
Aravind C
"Hugo Lefevre" <hu**********@tiscali.be> wrote in message
news:bu**********@news.worldonline.be...
dear,

I have a form (frmlogonaccounts.cs) with a combobox, which I want to fill up with the first column of a dataset. The dataset is created in the class
Login. My problem is the next : I make a new login in the form loginaccount which create a new login and give me a dataset (created by class login),
which I can see in my datagrid. But I want to fill up my combobox with only the name of the logon and I do this with an foreach. But when I see the
result the combobox is filled up with only the name of the column, not with the data in the dataset (as I said I see the data in the datagrid: so the
dataset is filled up).

What do I wrong ? Below you find the code in class Login and class
frmlogonaccount

Thank you very much.

Hugo

code Login :

public Login(out DataSet ds)
{
SqlSelectie = "select * from Login; ";
Database db = new Database();
SqlConnection conn = db.Opent();
SqlCommand cmd = new SqlCommand(SqlSelectie, conn);
SqlDataAdapter da = new SqlDataAdapter(SqlSelectie, conn);
ds = new DataSet();
da.Fill(ds, "Login");
conn.Close();
}

code frmlogonaccount :

DataSet ds = new DataSet("Login");
Login SqlLogin = new Login(out ds);
dataGrid1.SetDataBinding(ds, "Login");
///the next statement gives me the name of the column NOT the data
foreach (DataRow dr in ds.Tables["Login"].Rows)
cboListLogon.Items.Add(dr.Table.Columns[0]);

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
5
by: -elniniol999- | last post by:
I am DESPERATE for a quick reply.. have exhausted my options... i have a table called order details which contains: order id product id product name quantity unit price sale price
1
by: reidarT | last post by:
I am filling a combobox with data from a table. This is done with the code below. After update of the combobox I want to fill txtField2 with data from Field2 in the select-statement. How can I do...
0
by: reidarT | last post by:
I have found a good combobox with multiple fields The example shows filling the combobox from a listview, but I want to fill it with zip-code and cities from a database. The example is as follows:...
2
by: fstenoughsnoopy | last post by:
I have a customer order database and I need to pull a customers information, ie first name, last name, address, city, state, zip, phone, etc, into the oder table. i don't know how to go about...
8
by: kimtherkelsen | last post by:
Hi, I do this: this.comboBox.DataSource = myDataSet.Tables.Select("location_key = " + selectedLocationKey); this.comboBox.DisplayMember = "text"; this.comboBox.ValueMember =...
6
by: phytorion | last post by:
idk why this is giving me such a problem but here it is. I need to add a combobox to a continuous form. This combobox needs to allow the user to select between "S" and "T" for each record in this...
0
by: sixths3ns3 | last post by:
My DataGridView has two columns. Combobox Column 2 displays list based on Combobox Column 1 selected value. The code below works fine when I select a value on Column 1, and select a value on Column...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.