在vb.net中创建一个动态表 [英] Create a dynamic table in vb.net

查看:265
本文介绍了在vb.net中创建一个动态表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个动态表在Web表单内容占位符来显示。
我有一个简单的测试与下面的

I am trying to create a dynamic Table to display in web form content place holder. I have a simple test with the below

Private Function createmyTab() As Table
    Dim tbl As New Table
    For i As Integer = 10 To 0 Step -1
        Dim tr As TableRow = New TableRow()
        For j As Integer = 5 To 0 Step -1
            'i = i + 1
            Dim tc As TableCell = New TableCell()
            Dim txtBox As TextBox = New TextBox()
            txtBox.Text = "RowNo:" & i & " " & "ColumnNo:" & " " & j
            ' Add the control to the TableCell
            tc.Controls.Add(txtBox)
            ' Add the TableCell to the TableRow
            tr.Cells.Add(tc)
            Exit For
        Next j
        ' Add the TableRow to the Table
        tbl.Rows.Add(tr)
    Next i
    Return tbl
End Function  

的结果如下图所示。

The results are like below

Row 10 Col 5  Row 10 Col 4 Row 10 Col 3 Row 10 Col 2 Row 10 Col 1
Row 9  col 5  Row 9  col 4 Row 9 Col 3 Row 9 Col 2 Row 9 Col 1
Row 8  col 5  Row 8  col 4 Row 8 Col 3 Row 8 Col 2 Row 8 Col 1
Row 7  col 5  Row 7  col 4 Row 7 Col 3 Row 7 Col 2 Row 7 Col 1
Row 6  col 5  Row 6  col 4 Row 6 Col 3 Row 6 Col 2 Row 6 Col 1

和我想下面

Row 10 col 5  Row 9 col 5  Row 8 col 5  Row 7 Row 6
Row 10 col 4  Row 9 col 4  Row 8 col 4  .     .
Row 10 col 3  Row 9 col 3  Row 8 col 3  .     ..
Row 10 col 2  Row 9 col 2  Row 8 col 2  .     ...
Row 10 col 1  Row 9 col 1  Row 8 col 1  .     ....

这样做的目的,实际实现类似下面的 Image1的
(未按钮,但文本框)

Actual purpose of doing this to achieve like below Image1 (not buttons, but a text box)

我得到了正确的格式,但AA018 AA016 AA014的数字....应该是这样

I get the Numbers in correct format but AA018 AA016 AA014 ....should be like

AA018    AA017 AB018    AB017 AC018
AA016    AA015 AB016    AB015 AC016
AA014    AA013 AB014    AB013 AC014

可能有人请帮助我?
请参阅下面的图像来获得清晰的思路无效的布局

推荐答案

您需要提前创建你的细胞,然后填写他们得到你想要的垂直方面。

You need to create your cells ahead of time, then fill them in to get the vertical aspect that you want.

Private Function createmyTab() As Table
    Dim tbl As New Table
    For i As Integer = 10 To 0 Step -1
         Dim tr as TableRow = New TableRow()
         For j as Integer =5 to 0 Step -1
              Dim tc as TableCell = New TableCell()
              tr.Cells.Add(tc);
         Next j
    tbl.Rows.Add(tr)
    Next i

    For i as Integer = 10 to 0 Step -1
        For j As Integer = 5 To 0 Step -1
            Dim txtBox As TextBox = New TextBox()
            txtBox.Text = "RowNo:" & i & " " & "ColumnNo:" & " " & j
            ' Add the control to the TableCell
            TableCell tc = tbl.Rows(i).Cells(i)
            tc.Controls.Add(txtBox)
            Exit For
        Next j
    Next i
    Return tbl
End Function

另一种方式,以及将河套UP DOWN代替,扭转当前的循环计数器和反向的信息显示在code ...是这样的:

Another way as well would be to Loop UP instead of DOWN, reverse your current loop counters, and reverse the information being displayed in the code... like this:

Private Function createmyTab() As Table
    Dim tbl As New Table
    For i As Integer = 0 To 5 Step 1
        Dim tr As TableRow = New TableRow()
        For j As Integer = 0 To 10 Step 1
            'i = i + 1
            Dim tc As TableCell = New TableCell()
            Dim txtBox As TextBox = New TextBox()
            txtBox.Text = "RowNo:" & j & " " & "ColumnNo:" & " " & i
            ' Add the control to the TableCell
            tc.Controls.Add(txtBox)
            ' Add the TableCell to the TableRow
            tr.Cells.Add(tc)
            Exit For
        Next j
        ' Add the TableRow to the Table
        tbl.Rows.Add(tr)
    Next i
    Return tbl
End Function

很抱歉,如果这个code样品略低关闭或不能编译。我更多的是C#的人。

Sorry if this code sample is slighty off or doesn't compile. I am more of a C# person.

这篇关于在vb.net中创建一个动态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆