listbox 多列数据的问题,高手来
vb6.0中,listbox 可以通过设置columns属性设置为多列显示,但设置为多列后如何为每一列赋值(或读取每一)列的数据?
如何通过API取得外部程序中 多列listbox的数据?
1-3楼的都不对,2楼的,如果数据长度不一样,或者里面有汉字,你那个就不能用了
还有使用 LB_SETTABSTOPS 消息的也不考虑
如果有人能解决这个问题,愿意再加200分
不要跟我提listview,不考虑
可以参考这个:http://hi.baidu.com/%B7%BF%B6%F7%BA%EA/blog/item/3855eb2abdbe50325343c197.html 展开
把下面代码保存为“Form1.frm”,然后打开该文件,运行即可看到效果。
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "Form1"
ClientHeight = 3960
ClientLeft = 45
ClientTop = 435
ClientWidth = 7695
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3960
ScaleWidth = 7695
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "写入列数据"
Height = 495
Left = 4200
TabIndex = 4
Top = 3240
Width = 1575
End
Begin VB.ListBox List2
Height = 2580
Left = 5520
TabIndex = 3
Top = 120
Width = 2055
End
Begin VB.ListBox List1
Columns = 10
Height = 2580
Left = 120
TabIndex = 1
Top = 120
Width = 5295
End
Begin VB.CommandButton Command1
Caption = "获取列数据"
Height = 495
Left = 2280
TabIndex = 0
Top = 3240
Width = 1575
End
Begin VB.Label Label1
Caption = "Label1"
Height = 255
Left = 120
TabIndex = 2
Top = 2760
Width = 5175
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command1_Click()
Dim i As Integer, N As Integer, Counts As Integer
N = InputBox("你要获取第几列数据", Command2.Caption, 2)
If N = 0 Or List1.ListCount = 0 Then Exit Sub
List2.Clear
Counts = List1.Height / Me.TextHeight("a") '每列记录数
For i = (N - 1) * Counts To (N - 1) * Counts + Counts - 1 '第N列数据范围
List2.AddItem List1.List(i)
Next
End Sub
Private Sub Command2_Click()
Dim i As Integer, N As Integer, Counts As Integer
N = InputBox("你要写入第几列数据", Command2.Caption, 2)
If N = 0 Or List1.ListCount = 0 Then Exit Sub
List2.Clear
Counts = List1.Height / Me.TextHeight("a") '每列记录数
For i = (N - 1) * Counts To (N - 1) * Counts + Counts - 1 '第N列数据范围
List1.List(i) = Format(Rnd * 100, "0000")
Next
End Sub
Private Sub Form_Load()
Dim i As Integer
Randomize
For i = 1 To 100
List1.AddItem Format(i, "0000")
Next
End Sub
Private Sub List1_Click()
Label1 = List1.ListIndex + 1 & ":" & List1.Text
End Sub