gridview自动完成窗口应用程序c# [英] gridview autocomplete windows application c#

查看:68
本文介绍了gridview自动完成窗口应用程序c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有agridview我希望自动完成只有一个列但它适用于所有行单元格所有单元格是文本框我使用该代码



  public  AutoCompleteStringCollection AutoCompleteLoad()
{

AutoCompleteStringCollection str = new AutoCompleteStringCollection();

foreach (DataRow row in dt.Rows)
{
str.Add(Convert.ToString(row [ 1 ]));
}
return str;
}

private void dataGridView1_EditingControlShowing( object sender,DataGridViewEditingControlShowingEventArgs e)
{
int column = dataGridView1.CurrentCell.ColumnIndex;

string headerText = dataGridView1.Columns [ 1 ]。HeaderText;

if (headerText.Equals( pro))
{

TextBox tb = e.Control as TextBox;

if (tb!= null
{

tb.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

tb.AutoCompleteCustomSource = AutoCompleteLoad();

tb.AutoCompleteSource = AutoCompleteSource.CustomSource;

}

}
}





i仅限于列,但仍然可以使用所有单元格如何解决它?

解决方案

参考 - DataGridView Winform中的文本框自动完成功能 [ ^ ] 。

Quote:

你的if条件只是检查用户当前是否选择了第三列。



你想让所有专栏都可编辑吗?或者只是当前选定行中的一个单元格?如何通过表单中的另一个按钮触发编辑?在这种情况下,当编辑变为活动时,可以选择任何单元格吗?



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


i have agridview i hope to make auto complete for only one colum but it works with all row cells all the cells are textbox i use that code

  public AutoCompleteStringCollection AutoCompleteLoad()
        {

            AutoCompleteStringCollection str = new AutoCompleteStringCollection();

            foreach (DataRow row in dt.Rows)
            {
                str.Add(Convert.ToString(row[1]));
            }
            return str;
        }

        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {            
            int column = dataGridView1.CurrentCell.ColumnIndex;

            string headerText = dataGridView1.Columns[1].HeaderText;

            if (headerText.Equals("pro"))
            {

                TextBox tb = e.Control as TextBox;

                if (tb != null)
                {

                    tb.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

                    tb.AutoCompleteCustomSource = AutoCompleteLoad();

                    tb.AutoCompleteSource = AutoCompleteSource.CustomSource;

                }

            }
}



i make to only only column but still work with all cells how can i solve it ?

解决方案

Refer - Textbox Autocomplete in a DataGridView Winform[^].

Quote:

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.


这篇关于gridview自动完成窗口应用程序c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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