Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

虚表 ListView #205

Closed
huang1120 opened this issue Jul 2, 2024 · 9 comments
Closed

虚表 ListView #205

huang1120 opened this issue Jul 2, 2024 · 9 comments

Comments

@huang1120
Copy link

虚拟表 ListView 在加载一行数据的时候 OnListViewData 这个事件只会促发一次,如果有2行数据的情况下OnListViewData 就正常促发

@ying32
Copy link
Owner

ying32 commented Jul 8, 2024

测试并无问题啊,不知道你是怎么操作的。

这是我使用listviewvirtualdata例子测试的代码:

data := TTempItem{Caption: "标题", Sub1: "子项1", Sub2: "子项2", Sub3: "子项3", Sub4: "子项4", Sub5: "子项5", Checked: false}
tempData = append(tempData, data)
f.ListView.Items().SetCount(int32(len(tempData)))

@huang1120
Copy link
Author

` f.isWindows = runtime.GOOS == "windows"
fmt.Println("OnCreate")
f.SetWidth(800)
f.SetHeight(600)
f.ScreenCenter()
f.SetDoubleBuffered(true)

//============重绘表显示
f.Timer1 = vcl.NewTimer(f)
f.Timer1.SetOnTimer(f.OnTimer1Timer)
f.Timer1.SetEnabled(true)
f.Timer1.SetInterval(1000)
//==========================

f.ListView = vcl.NewListView(f)
f.ListView.SetAlign(types.AlClient)
f.ListView.SetParent(f)
f.ListView.SetViewStyle(types.VsReport)
f.ListView.SetOwnerData(true)
f.ListView.SetGridLines(true)
f.ListView.SetReadOnly(true)
f.ListView.SetRowSelect(true)
f.ListView.SetOnData(f.OnListView1Data)

// 要显示状态图标就得添加
// lazarus 2.2又出新bug了,,windows下ownerdata时会异常
f.ListView.SetCheckboxes(!f.isWindows)
//f.ListView.SetCheckboxes(true)

// windows下OwnerData不能显示checkbox
// linux和macOS在OwnerData下支持显示CheckBox
if f.isWindows {
	// 这里模拟显示
	f.stateImages = vcl.NewImageList(f)
	bmpFileName := "checkbox.png"
	if rtl.FileExists(bmpFileName) {
		pic := vcl.NewPicture()
		pic.LoadFromFile(bmpFileName)
		f.stateImages.AddSliced(pic.Bitmap(), 1, 2)
		pic.Free()
	}
	f.ListView.SetStateImages(f.stateImages)
	f.ListView.SetOnMouseDown(f.OnListView1MouseDown)
}

col := f.ListView.Columns().Add()
col.SetCaption("行号")
col.SetWidth(100)

col = f.ListView.Columns().Add()
col.SetCaption("子项1")
col.SetWidth(100)

col = f.ListView.Columns().Add()
col.SetCaption("子项2")
col.SetWidth(100)

col = f.ListView.Columns().Add()
col.SetCaption("子项3")
col.SetWidth(100)

col = f.ListView.Columns().Add()
col.SetCaption("子项4")
col.SetWidth(100)

col = f.ListView.Columns().Add()
col.SetCaption("子项5")
col.SetWidth(100)

//=============================== 这里 生成一个数据 下面就会出现 不会刷新 如果你生成2个数据就正常
tempData = make([]TTempItem, 1)
t := time.Now().UnixNano()
for i := 0; i < len(tempData); i++ {
	tempData[i].Caption = fmt.Sprintf("%d", i+1)
	tempData[i].Sub1 = fmt.Sprintf("子项1:%d", rand.Intn(1000000))
	tempData[i].Sub2 = fmt.Sprintf("子项2:%d", rand.Intn(1000000))
	tempData[i].Sub3 = fmt.Sprintf("子项3:%d", rand.Intn(1000000))
	tempData[i].Sub4 = fmt.Sprintf("子项4:%d", rand.Intn(1000000))
	tempData[i].Sub5 = fmt.Sprintf("子项5:%d", rand.Intn(1000000))
	tempData[i].Checked = false
}
go func() {
	index := 0
	for {
		vcl.ThreadSync(func() {
			// 这里目前是1 不会正常刷新显示 如果上面生成2条数据以上就正常
			tempData[0].Sub5 = strconv.Itoa(index)

			//tempData[1].Sub5 = strconv.Itoa(index)
			index++
		})
		time.Sleep(time.Second * 1)
	}
}()`

@ying32
Copy link
Owner

ying32 commented Jul 11, 2024

你这更新数据内容,需要调用控件的重绘(Repaint)之类的方法。

@huang1120
Copy link
Author

我那个已经调用一秒重绘一次了,问题就是一行数据就不会重绘,两行以上的数据就正常,你可以测试一下就知道了

@ying32
Copy link
Owner

ying32 commented Jul 12, 2024

我用你这个代码测试了下,没有发现问题,可以正常更新。你可以考虑下用最新的lazarus重新编译下liblcl看看。

@huang1120
Copy link
Author

我这里如果是两条数据以上也是正常刷新的,就是一条数据的时候才不正常刷新,永远是0

@ying32
Copy link
Owner

ying32 commented Jul 12, 2024

刚准备上传个新的liblcl,发现不行哦,得自己编译的才可以。

@huang1120
Copy link
Author

还是不行,会不会是win11的问题?这个问题不大,但是我觉得很奇怪,解决不了就不管他了 ,反正不影响使用

@ying32
Copy link
Owner

ying32 commented Jul 18, 2024

不知道,我在win10上编译的

@ying32 ying32 closed this as completed Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants