组合框第一记录 [英] Combo Box first record

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

问题描述

这是一个Win表单。


目前,第一个记录显示在组合框中。


我想要组合框为空白,当用户点击向下箭头

从列表中选择并点击列表中的项目时,该项目显示为组合中的
框。

This is for a Win form.

Currently, the first record is shown in the combo box.

I want the combo box to be blank and when the user clicks on the down arrow
to choose from the list and clicks on a item in the list then that item is
shown in the combo box.

推荐答案

将selectedIndex设置为-1

" Mike L" <钙*** @ nospam.nospam>在消息中写道

新闻:B5 ********************************** @ microsof t.com ...
Set the selectedIndex to -1
"Mike L" <Ca***@nospam.nospam> wrote in message
news:B5**********************************@microsof t.com...
这是一个Win表格。

目前,第一个记录显示在组合框中。

我希望组合框为空白,当用户点击向下箭头
从列表中选择并单击列表中的项目时,该项目将显示在组合框中。
This is for a Win form.

Currently, the first record is shown in the combo box.

I want the combo box to be blank and when the user clicks on the down
arrow
to choose from the list and clicks on a item in the list then that item is
shown in the combo box.



嗨Cadel,


感谢您的帖子。


你能提供一些代码片段来重现我们的问题吗?基于

我的测试,默认情况下,combobox.SelectedIndex属性的值为

-1。当应用程序启动时,组合框将不显示第一个

记录,它将只显示我们在combobox.Text属性中设置的内容。


我们可以只需将combobox.Text设置为空字符串以在组合框中显示空白

应用程序启动时。


希望这会有所帮助。


祝你好运,

Jeffrey Tan

微软在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证并且没有权利。

Hi Cadel,

Thanks for your post.

Can you provide me some code snippet to reproduce our your problem? Based
on my test, defaultly, combobox.SelectedIndex property will have value of
-1. And when the applicaiton startup, combobox will not display the first
record, it will just display what we set in the combobox.Text property.

We can just set combobox.Text to empty string to show up blank in combobox
when application startup.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


我将组合框文本设置为空字符串,但同样的问题。这是我的代码。


string sProc =" prGet_LicenseCode";

using(SqlConnection oCn = new SqlConnection(sConnString))

{

使用(SqlCommand oCmd = new SqlCommand(sProc,oCn))

{

oCn.Open();

oCmd.CommandType = CommandType.StoredProcedure;

oCmd.Parameters.Add(" @sLicenseYear",SqlDbType.NChar,6);

oCmd.Parameters [" @sLicenseYear"]。Value = txtLicYear.Text;


SqlDataAdapter oDa = new SqlDataAdapter();


oDa.SelectCommand = oCmd;

DataSet ds = new DataSet();

oDa.Fill(ds);


int numTables = ds.Tables.Count;

//没有表没有记录。

if(numTables< 1)

{

MessageBox.Show(找不到当年的许可证代码。,没有记录

found,MessageBoxButtons.OK);

}

其他

{

cboPrivilege.DataSou rce = ds.Tables [0];

cboPrivilege.DisplayMember =" LICENSE_CODE";

cboPrivilege.Text ="" ;;

}

}

"" Jeffrey Tan [MSFT]""写道:
I set the combo box text to empty string, but same problem. Here is my code.

string sProc = "prGet_LicenseCode";
using (SqlConnection oCn = new SqlConnection(sConnString))
{
using (SqlCommand oCmd = new SqlCommand(sProc, oCn))
{
oCn.Open();
oCmd.CommandType = CommandType.StoredProcedure;

oCmd.Parameters.Add("@sLicenseYear", SqlDbType.NChar, 6);
oCmd.Parameters["@sLicenseYear"].Value = txtLicYear.Text;

SqlDataAdapter oDa = new SqlDataAdapter();

oDa.SelectCommand = oCmd;
DataSet ds=new DataSet();
oDa.Fill(ds);

int numTables = ds.Tables.Count;
//No table no records.
if (numTables < 1)
{
MessageBox.Show("No License Codes found for that year.", "No record
found", MessageBoxButtons.OK);
}
else
{
cboPrivilege.DataSource = ds.Tables[0];
cboPrivilege.DisplayMember = "LICENSE_CODE";
cboPrivilege.Text = "";
}
}
""Jeffrey Tan[MSFT]"" wrote:
嗨Cadel,

感谢您的帖子。

您能否提供一些代码片段来重现我们的问题?基于我的测试,默认情况下,combobox.SelectedIndex属性的值为
-1。当应用程序启动时,组合框将不会显示第一个
记录,它只显示我们在combobox.Text属性中设置的内容。

我们可以将combobox.Text设置为空字符串应用程序启动时在组合框中显示空白。

希望这会有所帮助。

致以诚挚的问候,
Jeffrey Tan
Microsoft在线合作伙伴支持
获得安全! - www.microsoft.com/security
此帖子提供就像没有保证,也没有赋予任何权利。
Hi Cadel,

Thanks for your post.

Can you provide me some code snippet to reproduce our your problem? Based
on my test, defaultly, combobox.SelectedIndex property will have value of
-1. And when the applicaiton startup, combobox will not display the first
record, it will just display what we set in the combobox.Text property.

We can just set combobox.Text to empty string to show up blank in combobox
when application startup.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.



这篇关于组合框第一记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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