文本框自动完成在一个DataGridView

文本框自动完成在一个DataGridView

本文介绍了文本框自动完成在一个DataGridView Winform的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有我的DataGridView正确绑定到我的数据表,但是我想获取正确自动完成的文本框列的一个工作。该自动完成的工作,但我试图将其限制到只有一个DataGridView的列。目前,它要么会为每一列,或什么都没有。有任何想法吗?低于code。

 私人无效dataGridDetail_EditingControlShowing(对象发件人,DataGridViewEditingControlShowingEventArgs E)
    {
        如果(dataGridDetail.CurrentCell.ColumnIndex == 2)
        {
            无功源=新AutoCompleteStringCollection();
            的String []字符串数组= Array.ConvertAll< D​​ataRow中,字符串>(products.Select(),委托(DataRow的行){返回(字符串)行[code];});
            source.AddRange(字符串数组);

            文本框督促code = e.Control为文本框;
            如果(PROD code!= NULL)
            {
                督促code.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                督促code.AutoCompleteCustomSource =来源;
                督促code.AutoCompleteSource = AutoCompleteSource.CustomSource;

            }
        }
    }
 

解决方案

您如果条件是如果用户当前所选择的第三列只是检查。

你想使所有列编辑?或当前所选行中只有一个细胞?如何编辑由另一个按钮关闭该表格触发?在这种情况下,当编辑被激活的任意单元格可以选择?

您需要将索引到正确的列,并将其设置有自动完成。

I've got my DataGridView binding correctly to my datatable however I'm trying to get autocomplete to work correctly for one of the textbox columns. The autocomplete is working but I'm trying to restrict it to only one column on the datagridview. At the moment it either does it for every column, or nothing at all. Any ideas? Code below.

private void dataGridDetail_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if (dataGridDetail.CurrentCell.ColumnIndex == 2)
        {
            var source = new AutoCompleteStringCollection();
            String[] stringArray = Array.ConvertAll<DataRow, String>(products.Select(), delegate(DataRow row) { return (String)row["code"]; });
            source.AddRange(stringArray);

            TextBox prodCode = e.Control as TextBox;
            if (prodCode != null)
            {
                prodCode.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                prodCode.AutoCompleteCustomSource = source;
                prodCode.AutoCompleteSource = AutoCompleteSource.CustomSource;

            }
        }
    }
解决方案

Your if condition is just checking if the user has currently selected the third column.

Do you want to make all that column editable? or just one cell in the currently selected row? How is the edit triggered by another button off the form? In this case when the edit becomes active any cell could be selected?

You will need to index into the correct column and set it to have the autocomplete on.

这篇关于文本框自动完成在一个DataGridView Winform的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:33