在列表框中选择项目 [英] select Item in ListBox

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

问题描述

我的WinForm中有一个lisbox,其中从SQL数据库填充项目.
我想在WinForm加载期间从列表框中选择第一项.

I have a lisbox in my WinForm where items are filled from SQL database.
I want to select first item from listbox during the load in my WinForm.
How to do that?

推荐答案

将此代码添加到表单的加载事件中
Add this code to form''s load event
if (ListBox1.Items.Count > 0)
{
ListBox1.SelectedIndex = 0;
}


将SelectedIndex或SelectedItem属性设置为0
Set the SelectedIndex or SelectedItem property to 0


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

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