all groups > vb.net controls > november 2006 >
You're in the

vb.net controls

group:

better way to program than this?


Re: better way to program than this? tommaso.gastaldi NO[at]SPAM uniroma1.it
11/27/2006 2:28:02 PM
vb.net controls:
of course. You can place them in the class constructor.
Or make a sub that assigns them.

-t :)

Andr=E9 ha scritto:

[quoted text, click to view]
Re: better way to program than this? Tom Leylan
11/27/2006 5:22:11 PM
Andre:

Don't fail to take advantage of simple structured solutions. While you
could create a subclass (I wouldn't in this case) the easy solution is to
add a private function that returns a New TableCell that is pre-filled in.
Pass that function the text you want and it will be assigned as well. This
can be placed in a loop with a bit more tweaking (creating an array of text
values) but you probably don't have to go that far. So you end up with:

r.CellsAdd( MyNewTableCell(a))
r.CellsAdd( MyNewTableCell(b))
etc.

Tom


[quoted text, click to view]

better way to program than this? André
11/27/2006 7:33:52 PM
Hi,

I was wondering whether there is a better way to program code than this:
assume i need to create a lot of TabelCell with the same characterists
(HorizontalAlign, BackColor etc ...).

I can't use a loop (for/next) because the 'Text' is always different. What i
did was:

Dim c as TableCell
Dim r as TableRow
....


'first cell
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Center
c.BackColor = Drawing.Color.LightSteelBlue
c.Text=a
r.Cells.Add(c) ' add to row

'next cell
c = New TableCell
c.HorizontalAlign = HorizontalAlign.Center
c.BackColor = Drawing.Color.LightSteelBlue
c.Text=b
r.Cells.Add(c) ' add to row


etc ...


Is it not possible to define once all the characteristics of c instead of
repeating them for each cell?

Thanks
André

Re: better way to program than this? André
11/28/2006 12:00:00 AM
Thanks both

<tommaso.gastaldi@uniroma1.it> schreef in bericht
news:1164666482.507686.96720@f16g2000cwb.googlegroups.com...
of course. You can place them in the class constructor.
Or make a sub that assigns them.

-t :)

André ha scritto:

[quoted text, click to view]

Re: better way to program than this? Branco Medeiros
11/28/2006 6:37:54 AM
[quoted text, click to view]
<snip>

If the only thing that makes a cell appart from the others is the text,
you can pull the text from an array in a For Each /Next loop:

<aircode>
Dim CellText() AS String =3D { _
"Text1", "Text2", "Text3", ..., "TextN" _
}

For Each Text As String In CellText

Dim C as New TableCell
C.HorizontalAlign =3D HorizontalAlign.Center
C.BackColor =3D Drawing.Color.LightSteelBlue
C.Text=3D Text
...
... Add the cell to the row
...
Next
</aircode>

HTH.

Regards,

Branco.
AddThis Social Bookmark Button