none
关于COMBOBOX绑定数据的一些问题 RRS feed

  • 问题

  • 使用COMBOBOX的DisplayMember、ValueMember绑定数据后。
    1.我需要实现第一项为空,也就是selectIndex=-1;这种效果。
    因为我绑定后是要用来做查询的。
    2.我需要在用户使用COMBOBOX查询时,不能手动输入值,只能通过下拉来选择。
    请问这样怎么实现,谢谢。
    2010年1月26日 9:16

答案

  • 你好!
         1,可以使用Binding的Format事件来自己控制绑定数据的显示
         2,把ComboBox控件的DropDownStyle属性设置成DropDownList
    周雪峰
    • 已建议为答案 mazhou 2010年1月26日 10:19
    • 已标记为答案 刘汉威 2010年1月27日 3:54
    2010年1月26日 9:30
    版主

全部回复

  • 你好!
         1,可以使用Binding的Format事件来自己控制绑定数据的显示
         2,把ComboBox控件的DropDownStyle属性设置成DropDownList
    周雪峰
    • 已建议为答案 mazhou 2010年1月26日 10:19
    • 已标记为答案 刘汉威 2010年1月27日 3:54
    2010年1月26日 9:30
    版主
  • 绑定之前先插一条空的数据到顶部


    http://feiyun0112.cnblogs.com/
    2010年1月26日 9:36
    版主
  • 你好!
         1,可以使用Binding的Format事件来自己控制绑定数据的显示
         2,把ComboBox控件的DropDownStyle属性设置成DropDownList
    周雪峰

    关于第1点能不能给段代码 谢谢
    2010年1月26日 9:37
  • 你好!
         这里是一个TextBox的实例:    
       Binding b = new Binding
          ("Text", ds, "customers.custToOrders.OrderAmount");
       // Add the delegates to the event.
       b.Format += new ConvertEventHandler(DecimalToCurrencyString);
       b.Parse += new ConvertEventHandler(CurrencyStringToDecimal);
       text1.DataBindings.Add(b);
    

    周雪峰
    2010年1月26日 10:26
    版主
  • 你好!

    关于 1 和 2 只需要在绑定完成后设置下面两项就可以了。

    comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
    comboBox1.SelectedIndex = -1;

    知识改变命运,奋斗成就人生!
    2010年1月27日 1:37
    版主