Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Fill a list view
Message
From
15/07/2005 16:33:17
 
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
Environment:
C# 1.1
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01033186
Message ID:
01033196
Views:
21
David,

ListBox or ListView? ListBoxes can be DataBound, so the easiest way to do this is:
this.ListBox1.DataSource = MyDataView;  \\ This can also be a DataTable
this.ListBox1.DisplayMember = "MyColumnName";
~~Bonnie


>Trying to fill a listBox on a windows form, I've tried different approaches but have been unsuccessful. I've posted my code below, I'm just not getting any return result, in the listbox.
>
>
>string search_item = textBox1.Text.Trim();
> SqlConnection con1 =new SqlConnection(connection);
> SqlCommand cmd1 = new SqlCommand("sp_PMsearch_item", con1);
> cmd1.CommandType = CommandType.StoredProcedure;
> cmd1.Parameters.Add(new SqlParameter("@search_item", SqlDbType.VarChar));
> cmd1.Parameters["@search_item"].Value = search_item;
> SqlDataAdapter searchs = new SqlDataAdapter(cmd1);
> DataTable dtsearch = new DataTable();
> searchs.Fill(dtsearch);
> con1.Open();
> DataView searchresults = new DataView(dtsearch);
> foreach (DataRowView drv in searchresults)
>
>
>
> {
> this.listBox1.Items.Add(drv["item"].ToString());
> }
> con1.Close();
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform