文本框和列表框 [英] textbox and listbox

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

问题描述

你好,

我正在围绕这个问题四处走动,我希望有人可以帮助我。


我有一个列表框是从SQL Server数据库填充,包含大约600个项目,所有字符串。

我在同一表单上有一个文本框,我想显示哪个项目被选中。


在''OnSelectedIndexChanged''事件中,我需要具有文本框更新的代码到列表框中当前选择的任何值。


如果我使用代码:


TextBox1.Text = ListBox1.SelectedItem.toString


它会在文本框中显示不正确的项目。


如果我使用带有以下代码的数据行视图:

Dim drv As DataRowView = lBoxCP.SelectedItem

txtCPMain.Text = drv(" STR_CUTTING_PERMIT")

它运作良好,但点击几个不同的项目后,文本框开始显示不正确的项目。


SelectionMode设置为一。


有什么建议吗?

谢谢,

Amber

Hello,
I''m going around in circles with this problem and I hope someone can help me.

I have a listbox that is populated from a SQL Server database, with about 600 items, all strings.
I have a textbox on the same form, where I want to display which item is selected.

In the ''OnSelectedIndexChanged'' event, I need code that has the textbox update to whatever value is currently selected in the listbox.

If I use the code:

TextBox1.Text = ListBox1.SelectedItem.toString

it diplays the incorrect item in the textbox.

If I use a datarow view with the following code:
Dim drv As DataRowView = lBoxCP.SelectedItem
txtCPMain.Text = drv("STR_CUTTING_PERMIT")
It works quite well, but after clicking several different items, the text box starts showing incorrect items.

SelectionMode is set to One.

Any suggestions?
Thanks,
Amber

推荐答案

您好,


尝试将文本框和列表框绑定到同一数据源。

货币经理将保持同步。




------------ -

琥珀色 <一个******* @ discussions.microsoft.com>在消息中写道

新闻:C7 ********************************** @ microsof t.com ...
Hi,

Try binding the textbox and the listbox to the same datasource. The
currency manager will keep them in sync.

Ken
--------------
"amber" <an*******@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
你好,
我正在围绕这个问题四处走动,我希望有人可以帮助
我。
我有一个从SQL Server数据库填充的列表框,大约
600项,所有字符串。我在同一个表单上有一个文本框,我想要显示哪个项目是
被选中。
在''OnSelectedIndexChanged''事件中,我需要具有文本框$​​ b $ b更新的代码当前在列表框中选择了值。
如果我使用代码:

TextBox1.Text = ListBox1.SelectedItem.toString

它将不正确的项目显示在文本框。

如果我使用带有以下代码的数据行视图:
Dim drv As DataRowView = lBoxCP.SelectedItem
txtCPMain.Text = drv(" STR_CUTTING_PERMIT")框开始显示不正确的项目。
SelectionMode设置为一。

任何建议?
谢谢,
Amber
Hello,
I''m going around in circles with this problem and I hope someone can help me.
I have a listbox that is populated from a SQL Server database, with about 600 items, all strings. I have a textbox on the same form, where I want to display which item is selected.
In the ''OnSelectedIndexChanged'' event, I need code that has the textbox update to whatever value is currently selected in the listbox.
If I use the code:

TextBox1.Text = ListBox1.SelectedItem.toString

it diplays the incorrect item in the textbox.

If I use a datarow view with the following code:
Dim drv As DataRowView = lBoxCP.SelectedItem
txtCPMain.Text = drv("STR_CUTTING_PERMIT")
It works quite well, but after clicking several different items, the text box starts showing incorrect items.
SelectionMode is set to One.

Any suggestions?
Thanks,
Amber






尝试绑定文本框和列表框到同一个数据源。

货币经理将保持同步。




------------ -

琥珀色 <一个******* @ discussions.microsoft.com>在消息中写道

新闻:C7 ********************************** @ microsof t.com ...
Hi,

Try binding the textbox and the listbox to the same datasource. The
currency manager will keep them in sync.

Ken
--------------
"amber" <an*******@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...
你好,
我正在围绕这个问题四处走动,我希望有人可以帮助
我。
我有一个从SQL Server数据库填充的列表框,大约
600项,所有字符串。我在同一个表单上有一个文本框,我想要显示哪个项目是
被选中。
在''OnSelectedIndexChanged''事件中,我需要具有文本框$​​ b $ b更新的代码当前在列表框中选择了值。
如果我使用代码:

TextBox1.Text = ListBox1.SelectedItem.toString

它将不正确的项目显示在文本框。

如果我使用带有以下代码的数据行视图:
Dim drv As DataRowView = lBoxCP.SelectedItem
txtCPMain.Text = drv(" STR_CUTTING_PERMIT")框开始显示不正确的项目。
SelectionMode设置为一。

任何建议?
谢谢,
Amber
Hello,
I''m going around in circles with this problem and I hope someone can help me.
I have a listbox that is populated from a SQL Server database, with about 600 items, all strings. I have a textbox on the same form, where I want to display which item is selected.
In the ''OnSelectedIndexChanged'' event, I need code that has the textbox update to whatever value is currently selected in the listbox.
If I use the code:

TextBox1.Text = ListBox1.SelectedItem.toString

it diplays the incorrect item in the textbox.

If I use a datarow view with the following code:
Dim drv As DataRowView = lBoxCP.SelectedItem
txtCPMain.Text = drv("STR_CUTTING_PERMIT")
It works quite well, but after clicking several different items, the text box starts showing incorrect items.
SelectionMode is set to One.

Any suggestions?
Thanks,
Amber



嗨Amber,


你确定你使用受保护的事件''OnSelectedIndexChanged'',因为

比我认为你必须显示一些代码让我们知道你是什么

做什么。


Cor
Hi Amber,

Are you sure you use the protected event ''OnSelectedIndexChanged'' because
than I think you have to show some code to give us an idea what you are
doing.

Cor


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

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