vb.net ComboBox 重置为在windows应用程序中选择ComboBox的文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1254160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:19:57  来源:igfitidea点击:

ComboBox Reset to Select the Text of the ComboBox in windows Application

vb.netwinforms

提问by Babu Kumarasamy

I had added the items 1 2 3 to the combobox.

我已将项目 1 2 3 添加到组合框。

Then I gave the "Select" to the text of the combobox.

然后我给了组合框的文本“选择”。

How can I able to reset combobox to select the text("Select").

如何重置组合框以选择文本(“选择”)。

I had tried by giving -1 to the SelectedIndex. But it gives only Empty.

我曾尝试给 SelectedIndex 提供 -1。但它只给空。

This is for VB.NET Windows Application

这是用于 VB.NET Windows 应用程序

I have given an Image for your reference

我给了一张图片供您参考

Image path for the reference http://www.drivehq.com/file/df.aspx/publish/rk.babu/Files/ComboBoxReset.jpg

参考图片路径 http://www.drivehq.com/file/df.aspx/publish/rk.babu/Files/ComboBoxReset.jpg

回答by Hank

If the ComboBox1 property 'DropDownStyle' is set to 'Simple' or 'DropDown' then

如果 ComboBox1 属性 'DropDownStyle' 设置为 'Simple' 或 'DropDown' 那么

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    If ComboBox1.SelectedIndex = -1 Then ComboBox1.Text = "Select"
End Sub

will work. If set to 'DropDownList' then not...

将工作。如果设置为“DropDownList”,则不...

回答by adatapost

Set 0 value to SelectedIndex property. It will select 1st list item.

将 0 值设置为 SelectedIndex 属性。它将选择第一个列表项。

private Sub button1_Click(sender as object,e as  EventArgs) Handles button1.Click
  comboBox1.SelectedIndex = 0
End Sub

回答by Hand-E-Food

Just set the text property:

只需设置文本属性:

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    If ComboBox1.SelectedIndex = -1 Then ComboBox1.Text = "Select"
End Sub

回答by jane

combobox1.Text = "Select"

combobox1.Text = "选择"

and change the attribute of the combobox dropdownstyle to dropdown

并将组合框下拉样式的属性更改为下拉

回答by Perroni

for combobox1 dropdown list i use

对于我使用的 combobox1 下拉列表

combobox1.ResetText()
combobox1.SelectedIndex = -1

works here .

在这里工作。

回答by Srinu Rama Krishnan

double click the clear button in the design screen and type the following code to clear the value that is selected in the combo box.

双击设计屏幕中的清除按钮并键入以下代码以清除在组合框中选择的值。

private void button2_Click(object sender, EventArgs e)
    {

        c1.SelectedIndex = -1;
    }