Re: How to populate DataSet from List Box? by W
W
Tue Jun 28 20:11:29 CDT 2005
As a follow up, I played around with it and again, depending on what you
meant..
object[] o = new object[lb1.Items.Count];
lb1.Items.CopyTo(o,0);
DataTable dt = new DataTable("CuckooTable");
DataColumn dc = new DataColumn("CuckooColumn");
DataColumn dc2 = new DataColumn("CuckooColumn2");
dt.Columns.Add(dc);
dt.Columns.Add(dc2);
dt.Rows.Add(o);
However, this is another approach you can use if you have multiple columns.
Tell me a little more about what you need and I'll see what I can do:
private void GrabControls(Control ctrl)
{
foreach(Control ctrl in this.Controls)
{
if(ctrl.HasChildren)
{
GrabControls(ctrl);
}
else
{
if(typeof(ctrl) is ListBox)
{
object[] o = new object[(ctrl as ListBox).Items.Count];
lb1.Items.CopyTo(o,0);
DataTable dt = new DataTable("CuckooTable");//This needs to change each time
//If you want to add it to a dataset. Plus, you can just create a table
//and not have to add the columns at each pass, but if you're
//using a typed dataset than you don't need to do this at all.
DataColumn dc = new DataColumn("CuckooColumn");
DataColumn dc2 = new DataColumn("CuckooColumn2");
dt.Columns.Add(dc);
dt.Columns.Add(dc2);
dt.Rows.Add(o);
}
}
}
}
--
W.G. Ryan MVP (Windows Embedded)
TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"bpl via DotNetMonster.com" <forum@DotNetMonster.com> wrote in message
news:508821DE4CC10@DotNetMonster.com...
> I want to store the result sets for the 10 drop-down list boxes in a
DataSet
> object. How I can do it?