combo 与 textbox 配全做的一个选择框

Private Sub List2_Click()


Dim a, b As String
If T14.Text = "" Then
T14.Text = List2.Text
Else
a = InStr(T14.Text, List2.Text)
If a > 0 Then
If a > 1 Then
T14.Text = Replace(T14.Text, "|" & List2.Text, "")
Else
b = InStr(T14.Text, "|")
If b > 0 Then
T14.Text = Replace(T14.Text, List2.Text & "|", "")
Else
T14.Text = Replace(T14.Text, List2.Text, "")
End If
End If
Else
T14.Text = T14.Text & "|" & List2.Text
End If
End If


End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过使用ListBox和TextBox控件结合实现类似ComboBox的效果。具体步骤如下: 1.在窗体上添加一个ListBox和一个TextBox控件,设置ListBox的Visible属性为False。 2.在TextBox的TextChanged事件中,根据用户输入的内容动态筛选ListBox中的项,并将ListBox的Visible属性设置为True。 3.在ListBox的SelectedIndexChanged事件中,将所选项的值赋给TextBox,并将ListBox的Visible属性设置为False。 示例代码: ```csharp public partial class Form1 : Form { private List<string> dataList = new List<string> { "Apple", "Banana", "Cherry", "Durian", "Grape" }; public Form1() { InitializeComponent(); listBox1.DataSource = dataList; } private void textBox1_TextChanged(object sender, EventArgs e) { var filterData = dataList.Where(d => d.StartsWith(textBox1.Text, StringComparison.OrdinalIgnoreCase)).ToList(); listBox1.DataSource = filterData; listBox1.Visible = filterData.Any(); } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { textBox1.Text = listBox1.SelectedItem?.ToString(); listBox1.Visible = false; } } ``` 在上述示例中,我们使用了一个字符串列表作为数据源,在TextBox的TextChanged事件中根据用户输入的内容筛选出符合条件的项,并将ListBox的数据源设置为筛选结果,然后将ListBox的Visible属性设置为True。在ListBox的SelectedIndexChanged事件中,将所选项的值赋给TextBox,并将ListBox的Visible属性设置为False。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值