如何将垂直列放在动态表中? vb.net

时间:2015-12-22 07:37:05

标签: vb.net

我创建一个像这样的动态表:

'Item Number

    Dim conItem As New SqlConnection
    Dim cmdItem As New SqlCommand

    conItem = FunctionConnection()
    cmdItem.Connection = conItem
    cmdItem.CommandText = "GetItemNumber"
    cmdItem.CommandType = CommandType.StoredProcedure

    Dim ItemNumber As SqlDataReader = Nothing
    conItem.Open()
    ItemNumber = cmdItem.ExecuteReader()
    Dim Item As String = Nothing


    Do While ItemNumber.Read()

        Item = ItemNumber.GetValue(ItemNumber.GetOrdinal("ParagraphOrder"))

        'Station
        Dim conStation As New SqlConnection
        Dim cmdStation As New SqlCommand

        conStation = FunctionConnection()
        cmdStation.Connection = conStation

        cmdStation.CommandText = "GetStationValue"
        cmdStation.CommandType = CommandType.StoredProcedure
        cmdStation.Parameters.AddWithValue("@ParagraphOrder", Item)

        Dim RowsStation As SqlDataReader = Nothing
        conStation.Open()
        RowsStation = cmdStation.ExecuteReader()

        Dim Station As String = Nothing

        Do While RowsStation.Read()

            Station = RowsStation.GetValue(RowsStation.GetOrdinal("ActivityResource"))

            TBLCell = New TableCell
            TBLCell.Text = Station
            TBLCell.HorizontalAlign = HorizontalAlign.Center
            TBLCell.BorderStyle = BorderStyle.Solid
            TBLCell.BorderColor = System.Drawing.Color.Black
            TBLCell.BorderWidth = 1

            TBLRow.Cells.Add(TBLCell)

            TBLCell = New TableCell
            TBLCell.Text = Item
            TBLCell.HorizontalAlign = HorizontalAlign.Center
            TBLCell.BorderStyle = BorderStyle.Solid
            TBLCell.BorderColor = System.Drawing.Color.Black
            TBLCell.BorderWidth = 1

            TBLRow.Cells.Add(TBLCell)

        Loop
        conStation.Close()
    Loop
    conItem.Close()

图片在这里: enter image description here

我希望我的表有2列,名称中的数字是垂直的。 两个和两个,不是这样,一行。

我的表已经使用过程创建并为每个单元格获取值,但我想要一个包含两列而不是单行的垂直表。

“接收部件”号码。 非常感谢

1 个答案:

答案 0 :(得分:2)

首先,您需要定义column names,然后您需要创建将为每个值托管单元格的row。在伪代码中看起来像这样:

//Define table columns
var table = new Table();
//this define header titles
table.columns.add(new Column("Column 1"));
table.columns.add(new Column("Column 2"));
foreach(var object in collection)
{
     var row = new Row();
     var cell = new Cell(object.columnOneValue);
     // cell style could be define here, before it is added to its parent row.
     row.cells.add(cell);
     cell = new Cell(object.columnTwoValue);
     // cell style could be define here, before it is added to its parent row.
     row.cells.add(cell);
     table.rows.add(row);
}

希望这个简短的伪代码可以帮助您解决问题。