如何在listview中垂直转置数据 [英] How to tranpose data in listview vertically
问题描述
我是VB6的初学者。我的项目现在是解析原始数据,只获取所需的数据,并将其保存为CSV文件。我已经可以解析原始和在列表视图中查看我的问题是数据将水平输入在列表视图,当我在CSV文件中查看它与列表视图相同。
I am a beginner in VB6. My project right now is to parse a raw data and get only the needed data and save it as CSV file. I can already parse the raw and viewed in list view my problem is the data will inputted horizontally in listview and when i viewed it in CSV file the is same as the listview.
我现在的问题是我如何将数据放在listview 垂直
,而我解析数据?
My question now is how can i put the data in listview vertically
while i parse the data?
解析数据后在listview中的输出
below is the output in listview after parsing data
这是我将代码放入listview中的数据
This is my code to put the data in 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
推荐答案
向您的表单添加一个msflexgrid控件,您首先必须添加您可以在菜单中执行的组件。
to add a msflexgrid control to your form you first have to add the component which you can do in the menu.
在项目菜单中点击组件,然后在其中检查 Microsoft FlexGrid控件
In the project menu click on components and in there check the microsoft flexGrid control
然后看看下面的测试项目:
Then have a look at the following test project:
'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
当你点击按钮,它将首先水平填充网格,当你再次点击按钮将垂直填充网格,当你再次点击按钮将填充一些数据网格
When you click the button it will first fill the grid horizontally, when you click the button again it will fill the grid vertically, and when you click the button again it will fill the grid with some data
注意使用lngRow和lngCol以及它如何影响垂直填充的水平
Pay attention to the use of lngRow and lngCol and how it effects the horizontal of vertical filling
这篇关于如何在listview中垂直转置数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!