2015-12-22 49 views
0

我創建一個動態表這樣的:如何把垂直列放在動態表中? 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

我希望我的表有兩列,名稱與數字垂直。 兩個和兩個,不是這樣,一個單一的行。

我的表已創建與程序,並獲得每個單元格的值,但我想要一個垂直表,兩列不是一行。

「接收部件」的編​​號。 非常感謝

+0

我解決了:TablVerificari.Rows.Add(TBLRow) TBLRow =新表格 –

回答

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); 
} 

希望這個簡短的僞代碼可以幫助你解決你的問題。

+0

謝謝我解決 –