列表框项目问题 [英] Listbox item question

查看:77
本文介绍了列表框项目问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到您可以将项目作为对象添加到列表框中,这样您就可以访问多个属性,例如vb6中的itemindex。问题我

有一个问题是如何在对象

已被添加之后使列表框显示不同的文本。

解决方案

对于可能包含在列表框中的任何给定对象,它是somtimes

通常的做法是将ToString函数覆盖为默认文本
$ b显示$ b将是对象名称。如果对象包含您希望显示的值

,则可以从被覆盖的函数返回此值。


问候 - OHM

Bilal Abbasi写道:

我意识到你可以将项目作为对象添加到列表框中,这样你就可以访问不止一个属性,比如vb6中的itemindex 。
我的问题是如何在添加对象后使列表框显示不同的文本。




最好的问候 - OHMBest问候 - OHM On**********@BTInternet.Com


:)


你创建自己的类来添加这个类可以作为mutch的项目

vars as you need

并且必须覆盖字符串函数以显示

列表框中的文本

我将粘贴下面的代码


希望它有所帮助


eric


代码

\\

dim li as new clslistitem

li.text =" test"

listbox.items.add(li)

li = new clslistitem(" test2")

listbox.items.add(li)

//

如果你需要使用一件物品


\\

dim itemke as clslistitem

itemke = listbox.selecteditem

var = itemke.text

//

i还没有改变但它应该类似

尝试

listbox.selecteditem.text =" test"

listbox.refresh

班级

\\

Public Class clsListItem

Private Tekst As String

Private Tagske as String


私人物品作为对象


Public Sub New()

Tekst =""

Tagske =""

Omschrijvingske =""

End Sub


Public Sub New (ByVal te As Strin g)

Tekst = te

Tagske =""

Omschrijvingske =""

End Sub

Public Sub New(ByVal te As String,ByVal ta As String)

Tekst = te

Tagske = ta

Omschrijvingske =""

End Sub

Public Sub New(ByVal te As String,ByVal ta As String,ByVal oms As

String)

Tekst = te

Tagske = ta

Omschrijvingske = oms

End Sub
公共财产文本()为字符串

获取

返回Tekst

结束获取

设置(ByVal Value As String)

Tekst =价值

结束套件

结束物业


公开属性标签()为字符串

获取

返回Tagske

结束获取

设置(ByVal值为字符串)

Tagske =价值

结束集

结束物业

Public ReadOnly Property classe()As Integer

获取

返回0

结束获取

结束财产


公共财产Obj()作为对象

获取

返回objke

结束获取

设置(ByVal值为对象)

objke = Value

结束集

结束财产


公共覆盖函数ToString()作为字符串

返回Tekst

结束功能


结束班级

//

" Bilal Abbasi" < BA ***** @ chadbourne.com>在留言中写道

新闻:嗯************** @ TK2MSFTNGP11.phx.gbl ...

我意识到你可以将项目作为对象添加到列表框中,这样您就可以访问多个属性,例如vb6中的itemindex。问题
我有如何在已经添加
对象后使列表框显示不同的文本。


谢谢EricJ


我现在做的是

Dim cl作为cListItem = DirectCast(List1.Items(List1.SelectedIndex),

cListItem)


其中cListItem是我自己的类。


当我更改cl的text属性时,它确实是没有反映在

列表框中。





cl.text =" ***" ; &安培; cl.text


我试过list1.beginUpdate和list1.endUpdate


有什么想法吗?


" EricJ" <ericRéMo** @ ThiSomnipack.be>在消息中写道

news:3f ********************** @ reader1.news.skynet。是...

>

你创建自己的类作为一个项目添加,这个类可以作为mutch
vars,因为你需要
并且必须覆盖字符串功能才能在
列表框中显示文本
我将粘贴下面的代码

希望它有所帮助

> eric

代码
\\
dim li as new clslistitem
li.text =" test"
listbox.items.add( li)
li = new clslistitem(" test2")
listbox.items.add(li)
//
如果你需要使用一个项目
<作为clslistitem的dim itemke
itemke = listbox.selecteditem
var = itemke.text
//
我没有改变但它应该相似
尝试
listbox.selecteditem.text =" test"
listbox.refresh

班级
\\
公共类clsListItem
Private Tekst As String
Private Tagske As String

私人objk e As Object

Public Sub New()
Tekst =""
Tagske =""
Omschrijvingske =""
End Sub

Public Sub New(ByVal te As String)
Tekst = te
Tagske =""
Omschrijvingske =""
结束子

Public Sub New(ByVal te As String,ByVal ta As String)
Tekst = te
Tagske = ta
Omschrijvingske =""
End Sub
Public Sub New(ByVal te As String,ByVal ta As String,ByVal oms As
String)
Tekst = te
Tagske = ta
Omschrijvingske = oms
End Sub
公共属性文本()为字符串
获取
返回Tekst
结束获取
设置(ByVal值为字符串)
Tekst =价值
结束集
结束财产

公共财产标签()为字符串
获取
返回Tagske
结束获取
设置(ByVal值为字符串)
Tagske = Value
结束集
结束物业
公共ReadOnly物业classe()作为整数
获取
返回0
结束获取
结束物业

公共物业Obj()作为对象
获取
返回objke
结束获取
设置(ByVal值作为对象)
objke = Value
结束集
结束属性

公共覆盖函数ToString()作为字符串
返回Tekst
结束函数

结束类
//
" Bilal阿巴斯" < BA ***** @ chadbourne.com>在消息中写道
新闻:嗯************** @ TK2MSFTNGP11.phx.gbl ...

我意识到你可以添加项目到列表框作为对象,所以你可以
访问不止一个属性,如vb6中的itemindex。


问题我

有怎样的我怎么办在


对象

之后,列表框显示不同的文本。




I realize that you can add items to a list box as objects so you can have
access to more than just one property like the itemindex in vb6. Question I
have is how do I cause the listbox to show a different text after the object
has already been added.

解决方案

For any given object that may be contained in the listbox it is somtimes
common practice to override the ToString function as the default text which
is displayed will be the objects name. If the object contains a value that
you want displayed then you can return this from the overridden function.

Regards - OHM

Bilal Abbasi wrote:

I realize that you can add items to a list box as objects so you can
have access to more than just one property like the itemindex in vb6.
Question I have is how do I cause the listbox to show a different
text after the object has already been added.



Best Regards - OHMBest Regards - OHM On**********@BTInternet.Com


:)

you create your own class to add as an item this class can have as mutch
vars as you need
and has to have a overrides to string function to display the text in the
listbox
i''ll paste the code below

hope it helps

eric

code
\\
dim li as new clslistitem
li.text = "test"
listbox.items.add(li)
li = new clslistitem("test2")
listbox.items.add(li)
//
if you need to use an item

\\
dim itemke as clslistitem
itemke = listbox.selecteditem
var = itemke.text
//
i havent done altering but it should be similar
try
listbox.selecteditem.text = "test"
listbox.refresh
the class
\\
Public Class clsListItem
Private Tekst As String
Private Tagske As String

Private objke As Object

Public Sub New()
Tekst = ""
Tagske = ""
Omschrijvingske = ""
End Sub

Public Sub New(ByVal te As String)
Tekst = te
Tagske = ""
Omschrijvingske = ""
End Sub
Public Sub New(ByVal te As String, ByVal ta As String)
Tekst = te
Tagske = ta
Omschrijvingske = ""
End Sub
Public Sub New(ByVal te As String, ByVal ta As String, ByVal oms As
String)
Tekst = te
Tagske = ta
Omschrijvingske = oms
End Sub
Public Property Text() As String
Get
Return Tekst
End Get
Set(ByVal Value As String)
Tekst = Value
End Set
End Property

Public Property Tag() As String
Get
Return Tagske
End Get
Set(ByVal Value As String)
Tagske = Value
End Set
End Property
Public ReadOnly Property classe() As Integer
Get
Return 0
End Get
End Property

Public Property Obj() As Object
Get
Return objke
End Get
Set(ByVal Value As Object)
objke = Value
End Set
End Property

Public Overrides Function ToString() As String
Return Tekst
End Function

End Class
//
"Bilal Abbasi" <ba*****@chadbourne.com> wrote in message
news:um**************@TK2MSFTNGP11.phx.gbl...

I realize that you can add items to a list box as objects so you can have
access to more than just one property like the itemindex in vb6. Question I have is how do I cause the listbox to show a different text after the object has already been added.



Thanks EricJ

What I do right now is
Dim cl As cListItem = DirectCast(List1.Items(List1.SelectedIndex),
cListItem)

where cListItem is my own class.

When I change the text property of cl, it does not get reflected in the
listbox.

i.e.

cl.text = "***" & cl.text

I have tried list1.beginUpdate and list1.endUpdate

Any ideas?

"EricJ" <ericRéMo**@ThiSomnipack.be> wrote in message
news:3f**********************@reader1.news.skynet. be...

:)

you create your own class to add as an item this class can have as mutch
vars as you need
and has to have a overrides to string function to display the text in the
listbox
i''ll paste the code below

hope it helps

eric

code
\\
dim li as new clslistitem
li.text = "test"
listbox.items.add(li)
li = new clslistitem("test2")
listbox.items.add(li)
//
if you need to use an item

\\
dim itemke as clslistitem
itemke = listbox.selecteditem
var = itemke.text
//
i havent done altering but it should be similar
try
listbox.selecteditem.text = "test"
listbox.refresh
the class
\\
Public Class clsListItem
Private Tekst As String
Private Tagske As String

Private objke As Object

Public Sub New()
Tekst = ""
Tagske = ""
Omschrijvingske = ""
End Sub

Public Sub New(ByVal te As String)
Tekst = te
Tagske = ""
Omschrijvingske = ""
End Sub
Public Sub New(ByVal te As String, ByVal ta As String)
Tekst = te
Tagske = ta
Omschrijvingske = ""
End Sub
Public Sub New(ByVal te As String, ByVal ta As String, ByVal oms As
String)
Tekst = te
Tagske = ta
Omschrijvingske = oms
End Sub
Public Property Text() As String
Get
Return Tekst
End Get
Set(ByVal Value As String)
Tekst = Value
End Set
End Property

Public Property Tag() As String
Get
Return Tagske
End Get
Set(ByVal Value As String)
Tagske = Value
End Set
End Property
Public ReadOnly Property classe() As Integer
Get
Return 0
End Get
End Property

Public Property Obj() As Object
Get
Return objke
End Get
Set(ByVal Value As Object)
objke = Value
End Set
End Property

Public Overrides Function ToString() As String
Return Tekst
End Function

End Class
//
"Bilal Abbasi" <ba*****@chadbourne.com> wrote in message
news:um**************@TK2MSFTNGP11.phx.gbl...

I realize that you can add items to a list box as objects so you can have access to more than just one property like the itemindex in vb6.

Question I

have is how do I cause the listbox to show a different text after the


object

has already been added.




这篇关于列表框项目问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆