小弟在dataGridView的cell 的做資料輸入時,需實現像IE一樣的緩和技術,
如:在當前的cell中輸入一個字時,就會把之前輸入過的相關數据以下拉方式列出來,
供選擇使用;輸入的數字一多,下拉中顯示的值就一精确.
被逼的,老板要求必須這么做,但我們做過,小弟急用,
請各位大哥幫幫忙,給點方向,如果有實例及源碼更是万分感覺!
謝謝各位!

解决方案 »

  1.   

    就會把之前輸入過的相關數据以下拉方式列出來
    ==
    当前DataGridView的数据?需要遍历DataGridView的Cell
      

  2.   

    我提供一种方式给楼主参考:1、自定义一个数组或集合,来维护“缓存”,即把之前输入的有效值保存到下来。2、在SelectionChanged事件中,把单元格都转换成下拉框类型,并给下拉框绑定缓存数组。private void dataGridView1_SelectionChanged(object sender, EventArgs e)
    {
    DataGridViewComboBoxCell cbo = new DataGridViewComboBoxCell();
    cbo.DataSource = buffer;//buffer是存放有效缓存的数组(集合)//把当前单元格转换成ComboBoxCell 
    dataGridView1[dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex] = cbo;
    }//由于转换单元格类型时,可能触发类型错误,需击活DataError事件,事件内无代码
    private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
            {        }
    3、在EditingControlShowing事件中,把DataGridViewComboBoxCell转换成ComboBox控件,以使得能输入文本,并实现自动匹配的效果。private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
            {
                ComboBox c = e.Control as ComboBox;
                if (c != null)
                {
                    c.DropDownStyle = ComboBoxStyle.DropDown;
                    c.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                }
            }