Click here to Skip to main content
15,918,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Okay, so I have a list box that pulls all its data from a MySql server.

What I need to do is export the data the listbox pulls + other colums in the table to diffrent textboxes

Any help on how to do this?
Posted
Updated 19-Oct-10 4:22am
v2
Comments
Marc A. Brown 19-Oct-10 10:09am    
What have you tried?
Tunacha 19-Oct-10 10:12am    
ive tried searching google for about an hour and have no clue as to how to do this,
so i randomly tried
private void Form2_Load(object sender, EventArgs e)
{
myConnection.GetConnection();
DataSet sds = new DataSet();
MySqlCommand sql = new MySqlCommand("SELECT * FROM users", myConnection.GetConnection());
MySqlDataAdapter mydap = new MySqlDataAdapter(sql);
mydap.Fill(sds, "users");
this.UserList.DataSource = sds.Tables["users"];
this.UserList.DisplayMember = "name";


}

private void UserList_SelectedIndexChanged(object sender, EventArgs e)
{
Usernametxtbox.Text = UserList.DisplayMember = "name";
}



And that code fills the listbox and when i select any name in the listbox all i get is name

of course this was just a random shot in the dark try for me because i cant seem to find anything on google

1 solution

If you set UserList's ValueMember property equal to the name of your "users" table's ID field, you can retrieve that value using UserList.SelectedValue.
You can then use this to find the record you need to use to fill your textboxes.
 
Share this answer
 
Comments
Tunacha 19-Oct-10 10:42am    
im kind of a noob to c# how would i set the ValueMember
Marc A. Brown 19-Oct-10 10:46am    
The same way you set DisplayMember in the code you provided above.
Tunacha 19-Oct-10 10:49am    
Well when i do this
this.UserList.ValueMember = "id";

and then
Usernametxtbox.Text = UserList.ValueMember;


it just sets the Tet to id
Marc A. Brown 19-Oct-10 11:01am    
You misunderstand my solution. I meant for you to use SelectedValue as a means of retrieving the data you need to fill your textboxes. You'd use it to retrieve a record from the users table with the data (a SELECT statement with WHERE id={the value of SelectedValue}) or by creating a DataTable object (DataTable myDt = sds.Tables["users"] ought to do it or at least be close) and using it's Select(string) method to narrow down the number of rows (you would pass "id={whatever your selected id is}" to Select). This should at least get you close.
Marc A. Brown 19-Oct-10 11:17am    
Don't forget to accept the answer if, when all is said and done, it gives you what you needed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900