adding array item at run time

G

Guest

I will have a fixed number of columns in a tablecell array, but the number
rows will be dynamic. Is there a way to add array items at run time?
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
M

Marc Gravell

Thinking in terms of arrays will limit you severely... a List<T> where
T represents a row would be a lot more dynamic. In some cases,
DataTable may be an appropriate solution, since that will manage both
rows and columns for you with proven code.

Marc
 
G

Guest

Can a list contain a series of tablecells?
I iuse lists in coldfusion rather than arrays because the language is based
on lists. I've been avoiding lists in cs. Can i reference item in a list as i
would a 2dem array which is what i need here. I did not use a datatable
because i understood that a reader would be quicker.

i'm loading a large table and referencing the cells with the query
code:
while (rdr.Read()) {
iRow = Convert.ToInt32(rdr["rowNo"]) -1;
iCol = Convert.ToInt32(rdr["colNo"]);
TableCell td = this.tbl_ltspec.Rows[iRow].Cells[iCol];
td.Width = 10;
td.CssClass = "tbl_spec";
td.BackColor =
rfcs.fn_rtnSpectriumcolor(Convert.ToInt32(rdr["rating"]));
td.ToolTip = "Rating on " + rdr["dsplydate"].ToString() + " is "
+ rdr["rating"].ToString();
}
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
M

Marc Gravell

Can a list contain a series of tablecells?
I iuse lists in coldfusion rather than arrays because the language is based
on lists. I've been avoiding lists in cs. Can i reference item in a list as i
would a 2dem array which is what i need here.
List<T> allows type-safe access to any such list, i.e. List<TableCell>
list... however, if you are mixing your UI and DAL this way (which can
get confusing), then why not just use a TableRow for each row, which
has Cells collection, and (back a step) a Table which has a Rows
collection... i.e. if you are using controls, you shouldn't need to do
any of this yourself. Then you can look at myTable.Rows[3].Cells[2]
etc
I did not use a datatable
because i understood that a reader would be quicker.
Ultimately, I'm not a big fan of DataTable, but do you have any
evidence that the "2 minutes to implement" approach isn't sufficient?
It might be the most pragmatic route in, especially if you are binding
to a grid dynamically. Of course, if all you want to do is display
data, there may be other options too. If you aren't super-optimising,
then I'd keep it simple initially. If you *are* super-optimising (for
a good, proven reason; don't just assume it will be "slow"), then I
wouldn't be bothering with TableCell at all - I'd just be writing to
the raw ouput stream in the render pipeline.

Marc
 
G

Guest

like all things you weigh your choices to the economics of the problem.
a table is the best solution here as an array of tablecells that can be
accessed dynamicly and not in order. the code is compact, simple, and works
like lightening as is, except that C# will not let me create a dynamic array,
if i understand you right.
but to my question:
1. Can a list contain a series of tablecells?
can you create a 2dem list of tablecells and is it really faster or more
practical than an array of tablecells?

--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes


Marc Gravell said:
Can a list contain a series of tablecells?
I iuse lists in coldfusion rather than arrays because the language is based
on lists. I've been avoiding lists in cs. Can i reference item in a list as i
would a 2dem array which is what i need here.
List<T> allows type-safe access to any such list, i.e. List<TableCell>
list... however, if you are mixing your UI and DAL this way (which can
get confusing), then why not just use a TableRow for each row, which
has Cells collection, and (back a step) a Table which has a Rows
collection... i.e. if you are using controls, you shouldn't need to do
any of this yourself. Then you can look at myTable.Rows[3].Cells[2]
etc
I did not use a datatable
because i understood that a reader would be quicker.
Ultimately, I'm not a big fan of DataTable, but do you have any
evidence that the "2 minutes to implement" approach isn't sufficient?
It might be the most pragmatic route in, especially if you are binding
to a grid dynamically. Of course, if all you want to do is display
data, there may be other options too. If you aren't super-optimising,
then I'd keep it simple initially. If you *are* super-optimising (for
a good, proven reason; don't just assume it will be "slow"), then I
wouldn't be bothering with TableCell at all - I'd just be writing to
the raw ouput stream in the render pipeline.

Marc
 
M

Marc Gravell

1. Can a list contain a series of tablecells?
can you create a 2dem list of tablecells
Etrapolate... therefore, a List<List<T>> etc... however, if you *know*
your columns are fixed, you could treat your rows as a TableCell[],
and then keep a List said:
and is it really faster or more
practical than an array of tablecells?
more practical? Well, you've already stated that an array of table
cells doesn't work. So something that works trumps something that
works, certainly. However, just using Table.Rows[2].Cells[1] would be
even more practical that trying to do it yourself (it will amount to
about the same).
faster that a flat array (if that worked) - probably not, but it will
not be the pinch-point in your app; measure the performance, then iron
the kinks...

Also - look into the existing data-grid-view (or whatever)
combinations for web; they may do everything you need...

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top