Connecting Tech Pros Worldwide Forums | Help | Site Map

Array to Table with Variable Columns

a
Guest
 
Posts: n/a
#1: Nov 20 '05
Hey gang!

I have a specific problem, but a general answer may help. I am building a
web app which will display multiple UserControls on the screen. I want to
put them in a table that is X Columns by however many rows it takes to
complete the list.

I essentially need to add dim a new row, then a new cell, and continue
adding cells to the row until i get to the max_rows property, then add that
row to the table, dim a new row, and continue.

Is there any easy way of doing this with methods of arrays or arraylists, or
do I need to write out raw code? Any ideas or snippets??


Thanks!

kevin


Cor
Guest
 
Posts: n/a
#2: Nov 20 '05

re: Array to Table with Variable Columns


Hi A,

I was curious if something that I made for a winform would work on a webform
too, here an example (changed for a webform).

It is a calender, of course you can better use the calandercontrol, but as
example it is fine

\\\
Private mybutton(31) As Button
Private mylabel As New Label
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
For i = 0 To System.DateTime.DaysInMonth(2003, 11) - 1
mybutton(i) = New Button
mybutton(i).BackColor = Drawing.Color.AntiqueWhite
mybutton(i).Text = (i + 1).ToString
mybutton(i).Width = New Unit(30)
Me.panel1.Controls.Add(mybutton(i))
AddHandler mybutton(i).Click, AddressOf mybutton_Click
If (i + 1) Mod 5 = 0 Then
Me.panel1.Controls.Add(New LiteralControl("<BR>"))
End If
Next
Me.panel1.Controls.Add(New LiteralControl("<BR><BR>"))
Me.panel1.Controls.Add(mylabel)
End Sub
Private Sub mybutton_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim day As Button = DirectCast(sender, Button)
mylabel.Text = "The day is: " & day.Text
End Sub
///

Here is a link also,

http://msdn.microsoft.com/library/de...satruntime.asp


I hope this helps a little bit?

Cor

[color=blue]
>I have a specific problem, but a general answer may help. I am building a
>web app which will display multiple UserControls on the screen. I want to
>put them in a table that is X Columns by however many rows it takes to
>complete the list.[/color]
[color=blue]
>I essentially need to add dim a new row, then a new cell, and continue
>adding cells to the row until i get to the max_rows property, then add that
>row to the table, dim a new row, and continue.[/color]
[color=blue]
>Is there any easy way of doing this with methods of arrays or arraylists,[/color]
or[color=blue]
>do I need to write out raw code? Any ideas or snippets??[/color]




a
Guest
 
Posts: n/a
#3: Nov 20 '05

re: Array to Table with Variable Columns


I'll check it out!


I have been using this in the interim, but i didn't know if there was a
bettre way (less code):

Imports System.ComponentModel

Imports System.Web.UI

Imports System.Web.UI.WebControls

<DefaultProperty("Text"), ToolboxData("<{0}:TekTable
runat=server></{0}:TekTable>")> Public Class TekTable



Inherits System.Web.UI.WebControls.WebControl

Dim _text As String

Dim intMaxCols As Integer

Dim intMaxWidth As Integer

Dim alUC As New ArrayList

<Bindable(True), Category("Appearance"), DefaultValue("")> Property [Text]()
As String

Get

Return _text

End Get

Set(ByVal Value As String)

_text = Value

End Set

End Property

<Bindable(True), Category("Appearance"), DefaultValue("3")> Property
myMaxCols() As Integer

Get

Return intMaxCols

End Get

Set(ByVal Value As Integer)

intMaxCols = Value

End Set

End Property

<Bindable(True), Category("Appearance"), DefaultValue("800")> Property
myMaxWidth() As Integer

Get

Return intMaxWidth

End Get

Set(ByVal Value As Integer)

intMaxWidth = Value

End Set

End Property

<Bindable(True), Category("Appearance"), DefaultValue("")> Property myUC()
As ArrayList

Get

Return alUC

End Get

Set(ByVal Value As ArrayList)

alUC = Value

End Set

End Property

Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)

If Me.alUC.Count <> 0 Then

Dim tbl As New Table

Dim uc As UserControl

Dim r As TableRow

Dim c As TableCell

Dim int As Integer

Dim booAdded As Boolean = False

Dim i As Integer = 1

For int = 0 To alUC.Count - 1

booAdded = False

If i = 1 Then

r = New TableRow

End If

c = New TableCell

c.VerticalAlign = VerticalAlign.Top

c.Controls.Add(alUC.Item(int))

r.Cells.Add(c)

If i = intMaxCols Then

tbl.Rows.Add(r)

booAdded = True

i = 0

End If

i += 1

tbl.Rows.Add(r)

Next

If booAdded = False Then

tbl.Rows.Add(r)

End If

Me.Controls.Add(tbl)

End If

output.Write(Me.[Text])

Me.RenderChildren(output)

End Sub







Kevin

"Cor" <non@non.com> wrote in message
news:eKeCsawpDHA.2848@TK2MSFTNGP10.phx.gbl...[color=blue]
> Hi A,
>
> I was curious if something that I made for a winform would work on a[/color]
webform[color=blue]
> too, here an example (changed for a webform).
>
> It is a calender, of course you can better use the calandercontrol, but as
> example it is fine
>
> \\\
> Private mybutton(31) As Button
> Private mylabel As New Label
> Private Sub Page_Load(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles MyBase.Load
> Dim i As Integer
> For i = 0 To System.DateTime.DaysInMonth(2003, 11) - 1
> mybutton(i) = New Button
> mybutton(i).BackColor = Drawing.Color.AntiqueWhite
> mybutton(i).Text = (i + 1).ToString
> mybutton(i).Width = New Unit(30)
> Me.panel1.Controls.Add(mybutton(i))
> AddHandler mybutton(i).Click, AddressOf mybutton_Click
> If (i + 1) Mod 5 = 0 Then
> Me.panel1.Controls.Add(New LiteralControl("<BR>"))
> End If
> Next
> Me.panel1.Controls.Add(New LiteralControl("<BR><BR>"))
> Me.panel1.Controls.Add(mylabel)
> End Sub
> Private Sub mybutton_Click _
> (ByVal sender As Object, ByVal e As System.EventArgs)
> Dim day As Button = DirectCast(sender, Button)
> mylabel.Text = "The day is: " & day.Text
> End Sub
> ///
>
> Here is a link also,
>
>[/color]
http://msdn.microsoft.com/library/de...satruntime.asp[color=blue]
>
>
> I hope this helps a little bit?
>
> Cor
>
>[color=green]
> >I have a specific problem, but a general answer may help. I am building[/color][/color]
a[color=blue][color=green]
> >web app which will display multiple UserControls on the screen. I want[/color][/color]
to[color=blue][color=green]
> >put them in a table that is X Columns by however many rows it takes to
> >complete the list.[/color]
>[color=green]
> >I essentially need to add dim a new row, then a new cell, and continue
> >adding cells to the row until i get to the max_rows property, then add[/color][/color]
that[color=blue][color=green]
> >row to the table, dim a new row, and continue.[/color]
>[color=green]
> >Is there any easy way of doing this with methods of arrays or arraylists,[/color]
> or[color=green]
> >do I need to write out raw code? Any ideas or snippets??[/color]
>
>
>
>[/color]


Peter Huang
Guest
 
Posts: n/a
#4: Nov 20 '05

re: Array to Table with Variable Columns


Hi,

Here is an example, you may take a look to see if this

You may try to start a new form and set it to flow layout. Add two text
boxes and a button & this to the code-behind.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim i2 As Int32
Dim alUC As New ArrayList
Dim intMaxCols As Integer = CInt(TextBox2.Text)

For i2 = 0 To CInt(TextBox1.Text)
alUC.Add(i2)
Next

If alUC.Count > 0 Then
Dim tbl As New Table
Dim r As TableRow
Dim c As TableCell
Dim l As Label
Dim int As Integer
Dim i As Integer = 1
For int = 0 To alUC.Count - 1
If i = 1 Then
r = New TableRow
End If
c = New TableCell
c.VerticalAlign = VerticalAlign.Top
l = New Label
l.Text = alUC.Item(int)
c.Controls.Add(l)
r.Cells.Add(c)
If i = intMaxCols Or int = alUC.Count - 1 Then
tbl.Rows.Add(r)
i = 0
End If
i += 1
Next
Me.Controls.Add(tbl)
End If
End Sub


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Closed Thread