combox  中的值为
a aaa
b bbbb
c cccccc这个COMBOX是可以输入也可以选择的  当我选择的时候 比如我选择了 a aaa这一项目  那么在combox里显示的时候只显示aaa  如果我输入的时候 当我写上了c 那么就会弹出下拉菜单  c ccc这一项是被先中的`当我点击的时候 CCC会放入combox中  而不是显示 c ccc  请问这个要怎么写`因为下拉框的数量较`所以要从做成方法的角度去考虑~  在线等`   

解决方案 »

  1.   

    我试了下 觉得是简单问题 又没实现出来 。 if (comboBox1.Text != string.Empty)
     {
        comboBox1.Text = comboBox1.Text.Split(' ')[1].ToString();
     }都不知道这么赋值有什么不对 就是不会变
      

  2.   

    应该用combox和一个droplist组合起来就可以实现楼主所说的这个功能了
      

  3.   

            private void comboBox_KeyPress(object sender, KeyPressEventArgs e)
            {
                e.Handled = true;//取消键盘输入
            }是不是可以在这个事件里面处理输入的值
      

  4.   

    不行啊 试过了`  好像是要把combox弄成显示多列的玩意儿`~  不会弄`  期待`.....
      

  5.   


    /// <summary>
            /// 对ComboBox控件进行基础数据绑定
            /// </summary>
            /// <param name="strTable">来源数据表</param>
            /// <param name="cb">combobox控件名称</param>
            /// <param name="Conditions">条件</param>
            /// <param name="i">第几个字段</param>
            public void BindDropdownjclist(string strTable, ComboBox cb, string conditions,int i)
            {
                cn.Open();
                //实例化command对象
                OleDbCommand cmd = new OleDbCommand("select * from "+strTable+" where treetext='"+conditions+"'",cn);
                OleDbDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    cb.Items.Add(odr[i].ToString());
                }
                cn.Close();
            }LZ,我的问题是这样解决的。写个方法供你参考
      

  6.   

    现在的问题比较有意思  大家可以试试啊  情况是这样的`~  看代码
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;
    using System.Web.UI.WebControls;namespace combox
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
               
            }
            ListItem list = new ListItem("a aaa", "aaa");
            private void com()
            {
                this.comboBox1.Items.Add(list);
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                com();
            }
            private void a()
            {
                this.comboBox1.Text = list.Value;
            }
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
              
                this.button2.Text = list.Value;
                a();
            }    }
    }
    如果我跟踪的话~list.value的值为aaa  也就是说它有值了 可是combox的值不变
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;
    using System.Web.UI.WebControls;namespace combox
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
               
            }
            ListItem list = new ListItem("a aaa", "aaa");
            private void com()
            {
                this.comboBox1.Items.Add(list);
                //改动了这里
                this.comboBox1.Text = list.Value;
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                com();
            }
            private void a()
            {
                
            }
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                this.button2.Text = list.Value;
               
            }    }
    }
    改成这样就行了~  郁闷`  期待高手来帮忙
      

  7.   

    行了也不是说能完成了`就是在窗体加裁的时候  combox的值成了aaa  现在我要的是当我从下拉框里选a aaa的时候也会变成aaa 哎
      

  8.   

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                System.Threading.Thread Newcomtext = new System.Threading.Thread(new System.Threading.ThreadStart(doit));
                Newcomtext.Start();
            }        private void doit()
            {
                System.ComponentModel.ISynchronizeInvoke synchronizer = comboBox1;
                MethodInvoker invoker = new MethodInvoker(newtext);
                synchronizer.Invoke(invoker, null);
            }        private void newtext()
            {
                comboBox1.Text = comboBox1.Text.Split(' ')[1].ToString();
            }
      

  9.   

    combox可以直接设置属性的 
    一下子找不到了,我看看先
      

  10.   

    个人觉得重写ComboBox类比较容易实现
    public class SelfDefCombo : ComboBox
    {
    }
      

  11.   

    例子:using System;
    using System.Windows.Forms;namespace DataGridComboBoxColumn
    {
        /// <summary>
        /// DataGridComboBox 的摘要说明。
        /// </summary>
        public class DataGridComboBox:ComboBox
        {
            private const int WM_KEYUP = 0x101;        protected override void WndProc(ref System.Windows.Forms.Message message) 
            {            
                if (message.Msg == WM_KEYUP) 
                {
                    return;
                }            base.WndProc(ref message);
            }         //通过索引取得items的value。
            public string GetValueText(int index)
            {
                if(index < 0 || index >= base.Items.Count)
                {
                    //抛出索引超出异常
                    throw new IndexOutOfRangeException("无效索引。");
                }
                else
                {
                    string text = string.Empty;
                    int memIndex =  -1;
                    try
                    {
                        base.BeginUpdate();
                        memIndex = base.SelectedIndex;
                        base.SelectedIndex = index;
                        text = base.SelectedValue.ToString();
                        base.SelectedIndex = memIndex;
                    }
                    catch
                    {}
                    finally
                    {
                        base.EndUpdate();
                    }
                    return text;
                }            
            }
            //通过索引取得items的text        
            public string GetDisplayText(int index)
            {
                if(index <0 || index >=base.Items.Count)
                {
                    //抛出索引超出异常
                    throw new IndexOutOfRangeException("无效索引。");
                }
                else
                {
                    string text = string.Empty;
                    int memIndex = -1;
                    try
                    {
                        base.BeginUpdate();
                        memIndex = base.SelectedIndex;
                        base.SelectedIndex = index;
                        text = base.Text.ToString();
                        base.SelectedIndex = memIndex;
                    }
                    catch
                    {}
                    finally
                    {
                        base.EndUpdate();
                    }
                    return text;
                }
            }
            //通过value取得items的text
            public string GetDisplayText(object value)
            {            
                string text = string.Empty;
                int memIndex= -1;
                try
                {
                    base.BeginUpdate();
                    memIndex = base.SelectedIndex;
                    base.SelectedValue = value.ToString();
                    text = base.Text.ToString();                
                    base.SelectedIndex = memIndex;
                }
                catch
                {}
                finally
                {
                    base.EndUpdate();
                }
                return text;
            }
            //循环获取items的text
            public string[] GetDisplayText()
            {
                string[] text = new string[base.Items.Count];
                int memIndex = -1;
                try
                {
                    base.BeginUpdate();
                    memIndex = base.SelectedIndex;
                    for(int i=0;i<base.Items.Count;i++)
                    {
                        base.SelectedIndex = i;
                        text[i] = base.Text.ToString();                    
                    }
                    base.SelectedIndex = memIndex;
                }
                catch
                {}
                finally
                {
                    base.EndUpdate();
                }
                return text;
            }
        }}
    节选自 http://www.cnblogs.com/ami/archive/2006/07/20/455360.html
      

  12.   

     private void comboBox1_KeyUp(object sender, KeyEventArgs e)
            {
                string old = comboBox1.Text;
                for (int i = 0; i < comboBox1.Items.Count; i++)
                    if (comboBox1.Items[i].ToString().IndexOf(comboBox1.Text + " ") == 0)
                    {
                        comboBox1.BeginUpdate(); 
                        comboBox1.SelectedIndex = i;
                        comboBox1.DroppedDown = true;
                        comboBox1.Text = old;
                        comboBox1.Select(comboBox1.Text.Length, 0);  
                        comboBox1.EndUpdate();
                        break;
                    }
            }        private void comboBox1_DropDownClosed(object sender, EventArgs e)
            {
                string s=comboBox1.Items[comboBox1.SelectedIndex].ToString();
                comboBox1.Text = s.Remove(0, s.IndexOf(" ") + 1);
            }
      

  13.   

    这是比较简单和简陋的写法,不过基本可以达到要求
    比如按个c 自动下拉而且选中c ccc到状态,然后回车就把ccc赋值回去了
    不过还是有点小问题,比如鼠标选择
      

  14.   

    用listItems(value,。。)这个可以不? 我在看楼上各位的东西` 在试
      

  15.   


    Mark下~个人认为必须Invoke,这个是正解!!!
    运行过程中动态改变控件的属性了,必须invoke做...
      

  16.   

    这是由于.net的安全机制引发的
    子线程是不能操作UI线程的
    方法:
    用异步委托做个Invoke方法 
      

  17.   

    不知道楼主想表达什么,选a aaa变成aaa,这是什么意思,,有什么规律????????
      

  18.   

    下拉框拉出来的时候   下面会显示  a aaa
                                 b bbb
                                 c ccc
    当我点击了其中一项时,比如我选了a aaa 那么在combox里面应该显示 a aaa对吧  现在是想下拉框出现时显示a aaa 当我点击选择了以后  在combox里显示 aaa  不知道我说明白了没有
      

  19.   

    我想lz其实就是想做个类似只需要输入产品ID或产品缩写自动下拉出产品ID或产品缩写和产品名称,选择完后实际存到时产品名称方便检索的产品录入的这样一个东西
      

  20.   

    我晕菜`~这CSDN  怎么放图片啊 ~~  我可以把图片加上去给你们看看的
      

  21.   


     this.button2.Text = list.Value;
    这句话是不是搞错了,应该是
    this.comboBox1.Text= list.Value;吧?
      

  22.   

    没有错`  因为我多放一个button 这样可以跟combox对比``  我点button1时候完成的是效果` 可是combox不变` 我以为没有变呢 就在改变combox里面值的时候改变button中的text  这样就能对比了