473,394 Members | 1,706 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,394 software developers and data experts.

Array to Table with Variable Columns

a
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
Nov 20 '05 #1
3 1442
Cor
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

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, ordo I need to write out raw code? Any ideas or snippets??



Nov 20 '05 #2
a
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" <no*@non.com> wrote in message
news:eK**************@TK2MSFTNGP10.phx.gbl...
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

I have a specific problem, but a general answer may help. I am building aweb app which will display multiple UserControls on the screen. I want toput 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 thatrow 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??


Nov 20 '05 #3
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.

Nov 20 '05 #4

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

Similar topics

4
by: Haydnw | last post by:
Hi, I'd like to put a load of database results (several rows for 5 fields) into a two-dimensional array. Now, this may be a really stupid question, but can someone give me a pointer for how to...
33
by: Peace | last post by:
I am having trouble writing code to turn an array into a delimited string. Dim splitout As String splitout = Join(DataArray(rows, columns), " ") rows and columns are integers representing rows...
3
by: rodchar | last post by:
Hey all, I was wondering, can I databind my text box to an array, if so what would my datasource and member look like? thanks in advance, rodchar
4
by: Jim Shaffer | last post by:
Perhaps I have the wrong construct, or misunderstand arrays in vb (2003).... I've loaded a two-dimensional array (168 by 28) into memory as AcctArray. {Dim AcctArray (500,28) as string...} The...
14
by: Peter | last post by:
Is there a fast way to move data from DataTable into double array, or do I have to spin through every record and column? I have five tables and I need to merge these tables column wise, each table...
1
by: Bernard Dhooghe | last post by:
The documentation (Administrative API Reference, 8.2, PDF format) says page 520: "The rest of the record is dependent upon the record type and the table descriptor record defined for the table."...
0
by: mwenz | last post by:
I am trying to update an Access table using OLEDB in VB.Net 2005. I can add rows but I cannot update them. Code to instantiate the Access database and table... Dim conn As New...
33
by: Adam Chapman | last post by:
Hi, Im trying to migrate from programming in Matlab over to C. Im trying to make a simple function to multiply one matrix by the other. I've realised that C can't determine the size of a 2d...
2
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
7
by: ShenPixel | last post by:
I've been working with the following code and would like to output the results into a customizable column variable, how would I go about doing such a thing, thanks in advance for any help. I hard...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.