如何在listview中垂直转置数据

时间:2014-03-26 03:50:29

标签: listview csv vb6

我是VB6的初学者。我的项目现在是解析原始数据并仅获取所需数据并将其另存为CSV文件。我已经可以解析原始和查看列表视图我的问题是数据将在列表视图中水平输入,当我在CSV文件中查看时,它与列表视图相同。

我现在的问题是,在解析数据时,如何将数据放入listview vertically

下面的

是解析数据后列表视图中的输出

enter image description here

这是我将数据放入listview的代码

If cmd_req_flow <> "" And cmd_req_flow_a <> "" Then
                                txt_date = cmd_date_time_a
                                txt_parsereq = cmd_totalparsedreq_a - cmd_totalparsedreq
                                txt_flowtotal = cmd_flow_total_a
                                txt_reqflow = cmd_req_flow_a
                                txt_aia = cmd_aia_a - cmd_aia
                                txt_air = cmd_air_a - cmd_air
                                txt_cer = cmd_cer_a - cmd_cer
                                txt_cla = cmd_cla_a - cmd_cla
                                txt_clr = cmd_clr_a - cmd_clr
                                txt_dsa = cmd_dsa_a - cmd_dsa
                                txt_dsr = cmd_dsr_a - cmd_dsr
                                txt_dwa = cmd_dwa_a - cmd_dwa
                                txt_dwr = cmd_dwr_a - cmd_dwr
                                txt_ida = cmd_ida_a - cmd_ida
                                txt_idr = cmd_idr_a - cmd_idr
                                txt_noa = cmd_noa_a - cmd_noa
                                txt_nor = cmd_nor_a - cmd_nor
                                txt_pua = cmd_pua_a - cmd_pua
                                txt_pur = cmd_pur_a - cmd_pur
                                txt_rsa = cmd_rsa_a - cmd_rsa
                                txt_rsr = cmd_rsr_a - cmd_rsr
                                txt_ula = cmd_ula_a - cmd_ula
                                txt_ulr = cmd_ulr_a - cmd_ulr

                                     Set itmX = ListView1.ListItems.Add(, , txt_date)
                                                itmX.SubItems(1) = txt_parsereq
                                                itmX.SubItems(2) = txt_flowtotal
                                                itmX.SubItems(3) = txt_reqflow
                                                itmX.SubItems(4) = txt_aia
                                                itmX.SubItems(5) = txt_air
                                                itmX.SubItems(6) = txt_cer
                                                itmX.SubItems(7) = txt_cla
                                                itmX.SubItems(8) = txt_clr
                                                itmX.SubItems(9) = txt_dsa
                                                itmX.SubItems(10) = txt_dsr
                                                itmX.SubItems(11) = txt_dwa
                                                itmX.SubItems(12) = txt_dwr
                                                itmX.SubItems(13) = txt_ida
                                                itmX.SubItems(14) = txt_idr
                                                itmX.SubItems(15) = txt_noa
                                                itmX.SubItems(16) = txt_nor
                                                itmX.SubItems(17) = txt_pua
                                                itmX.SubItems(18) = txt_pur
                                                itmX.SubItems(19) = txt_rsa
                                                itmX.SubItems(20) = txt_rsr
                                                itmX.SubItems(21) = txt_ula
                                                itmX.SubItems(22) = txt_ulr
                                        Call clear_fourth
                                        Call clear_five
                                        Call clear_first

                                        Call clear_field_name
                                        Call clear_value
                                        txt_sec = 0
                                        txt_t1 = ""
                                        txt_t2 = ""
                                        txt_st = ""

                                               cmd_date_time = cmd_date_time_a
                                               cmd_ulr = cmd_ulr_a
                                               cmd_aia = cmd_aia_a
                                               cmd_dsa = cmd_dsa_a
                                               cmd_rsr = cmd_rsr_a
                                               cmd_dsr = cmd_dsr_a
                                               cmd_noa = cmd_noa_a
                                               cmd_pur = cmd_pur_a
                                               cmd_dwa = cmd_dwa_a
                                               cmd_clr = cmd_clr_a
                                               cmd_cla = cmd_cla_a
                                               cmd_nor = cmd_nor_a
                                               cmd_pua = cmd_pua_a
                                               cmd_totalparsedreq = cmd_totalparsedreq_a
                                               cmd_rsa = cmd_rsa_a
                                               cmd_air = cmd_air_a
                                               cmd_ida = cmd_ida_a
                                               cmd_ula = cmd_ula_a
                                               cmd_cer = cmd_cer_a
                                               cmd_flow_total = cmd_flow_total_a
                                               cmd_idr = cmd_idr_a
                                               cmd_dwr = cmd_dwr_a
                                               cmd_req_flow = cmd_req_flow_a
                                        Call clear_second
                            End If

1 个答案:

答案 0 :(得分:1)

要向表单添加msflexgrid控件,首先必须添加可在菜单中执行的组件。

项目菜单中点击组件,然后检查 microsoft flexGrid控件

然后看看以下测试项目:

'1 form with:
'  MSFlexGrid: name=MSFlexGrid1
'  Command button: name=Command1
Option Explicit

Private Sub Command1_Click()
  Static lngMode As Long
  'process the right modes
  Select Case lngMode
    Case 0
      FillHorizontal
    Case 1
      FillVertical
    Case 2
      FillData
  End Select
  'set next mode
  lngMode = (lngMode + 1) Mod 3
End Sub

Private Sub Form_Load()
  With MSFlexGrid1
    .FixedRows = 0
    .FixedCols = 0
    .Rows = 7
    .Cols = 12
  End With 'MSFlexGrid1
End Sub

Private Sub Form_Resize()
  Dim sngWidth As Single, sngHeight As Single
  Dim sngCmdHeight As Single, sngGrdHeight As Single
  sngWidth = ScaleWidth
  sngHeight = ScaleHeight
  sngCmdHeight = 495
  sngGrdHeight = sngHeight - sngCmdHeight
  MSFlexGrid1.Move 0, 0, sngWidth, sngGrdHeight
  Command1.Move 0, sngGrdHeight, sngWidth, sngCmdHeight
End Sub

Private Sub FillHorizontal()
  Dim lngRow As Long, lngCol As Long
  With MSFlexGrid1
    For lngCol = 0 To .Cols - 1
      For lngRow = 0 To .Rows - 1
        .TextMatrix(lngRow, lngCol) = CStr(lngRow * .Cols + lngCol)
      Next lngRow
    Next lngCol
  End With 'MSFlexGrid1
End Sub

Private Sub FillVertical()
  Dim lngRow As Long, lngCol As Long
  With MSFlexGrid1
    For lngCol = 0 To .Cols - 1
      For lngRow = 0 To .Rows - 1
        .TextMatrix(lngRow, lngCol) = CStr(lngCol * .Rows + lngRow)
      Next lngRow
    Next lngCol
  End With 'MSFlexGrid1
End Sub

Private Sub FillData()
  With MSFlexGrid1
    .Clear
    .TextMatrix(0, 0) = "Food"
    .TextMatrix(0, 1) = "Drinks"
    .TextMatrix(1, 0) = "Cake"
    .TextMatrix(1, 1) = "Water"
    .TextMatrix(2, 0) = "Cup cake"
    .TextMatrix(2, 1) = "Soft drinks"
    .TextMatrix(3, 0) = "Spaghetti"
    .TextMatrix(3, 1) = "Orange juice"
    .TextMatrix(4, 0) = "Canton"
    .TextMatrix(4, 1) = "Coffee"
    .TextMatrix(5, 0) = "Abodo"
    .TextMatrix(5, 1) = "Tea"
  End With 'MSFlexGrid1
End Sub

单击按钮时,它将首先水平填充网格,当您再次单击该按钮时,它将垂直填充网格,当您再次单击该按钮时,它将使用一些数据填充网格

注意使用lngRow和lngCol以及它如何影响垂直填充的水平