473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

adding array item at run time

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
Sep 5 '07 #1
4 1772
Thinking in terms of arrays will limit you severely... a List<Twhere
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

Sep 5 '07 #2
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
"Marc Gravell" wrote:
Thinking in terms of arrays will limit you severely... a List<Twhere
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

Sep 6 '07 #3
On 6 Sep, 14:30, WebBuilder451
<WebBuilder...@discussions.microsoft.comwrote:
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<Tallows 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

Sep 6 '07 #4
1. Can a list contain a series of tablecells?
A List<Tcan contain a series of T, so a List<TableCellcan contain
a series of TableCell, yes.
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<TableCell[]>
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

Sep 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: David | last post by:
I have an array that contains numbers in string elements , i want to convert this to integers, i have made a for loop that uses the number of elements in the array and then adds 0, thereby...
0
by: Stephen | last post by:
I have been getting on well with help from this forum trying to create an array list and work with it. Everything is working fine apart from displaying my array list items into the labels in my...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
5
by: Water Cooler v2 | last post by:
I know that we can add a single name value entry in app.config or web.config in the configuration/configSettings/appSettings section like so: <add key="key" value="value" /> Question: I want...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
10
by: Phat G5 (G3) | last post by:
I was toying around with adding a new method to the Array class. It works fine in FF but not in Safari. I have no idea in IE. I have not gotten that far yet. Array.prototype.find =...
9
by: Kiamari | last post by:
here's what i have to do: Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a...
6
by: npankey | last post by:
I've started experimenting with template metaprogramming in a small project of mine. What I'm trying to accomplish is to generate a static array of templated objects that get specialized based on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.