views:

44

answers:

1

I have almost 200 listboxes. I'm changing their visibility according to my variables from database.

So I thought that, I prepared a arraylist. like this

ListBox[] lbs = this.Controls.OfType<ListBox>().ToArray();

And used like this.

for (int idx = 0; idx < Convert.ToInt32(ds.Tables[j].Rows[i][2])*12; idx++)
     lbs[idx].Visible = true;

This codes are written to comboboxchange. Now everything is okay. But;

example;

first time I changed combobox

1-20 listboxes visible=true

I changed combobox again

not 1-20. 20,40 changing :S How can it be, can u tell me an alternative array list type, or another way?

+1  A: 

I'm not sure why you need 200 listboxes at one time - did your customers do something to make you mad?

200 listboxes is a large number of listboxes (that's a polite way of saying "way too darn large") to have anywhere, especially if (as I suspect) most of them are invisible at any one time.

It looks like you already have the data (in table form) for these listboxes in a DataSet. It's best you leave your data in that form, and only create-and-fill listboxes as the program needs them.

In other words, rather than creating-and-filling 200 listboxes and then having only some of them visible at any one time, it would be better to just create the listboxes that you need when you need them and dispose of them when you're done (and don't keep the unused ones around and invisible).

MusiGenesis