简体   繁体   English

创建自定义datagridview的列类型

[英]Create custom datagridview's Column type

i just create a custom control, i want this control implement to datagridview's column. 我只是创建一个自定义控件,我希望此控件实现到datagridview的列。

but how? 但是如何? is it possible? 可能吗?

在此处输入图片说明

for example, i want add my column type like "DataGridViewCustomTextBoxColumn" 例如,我要添加“ DataGridViewCustomTextBoxColumn”之类的列类型


this is my current code. 这是我当前的代码。

 private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {    
        if (dataGridView1.CurrentCell.ColumnIndex == 0)
        {

            Connection.ConnectionClose();
            Connection.ConnectionOpen();

            var source = new List<string>();
            string queryItem = "SELECT * FROM ITEM ";              

            Connection.command = new OleDbCommand(queryItem, Connection.conn);
            Connection.command.CommandType = CommandType.Text;
            AutoCompleteStringCollection kode = new AutoCompleteStringCollection();

            reader = Connection.command.ExecuteReader();

            if (reader.HasRows == true)
            {
                while (reader.Read())
                {
                    //kode.Add(reader["code"].ToString());
                    source.Add(reader["code"].ToString());
                }
            }
            else
            {
                MessageBox.Show("Data not Found");
            }
            reader.Close();
            //ComboBox txtBusID = e.Control as ComboBox;
            TextBox kodeTxt = e.Control as TextBox;
            if (kodeTxt != null)
            {
                kodeTxt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                kodeTxt.AutoCompleteCustomSource = kode;
                kodeTxt.AutoCompleteSource = AutoCompleteSource.CustomSource;
            }

        }
  }

what i tried.. like this. 我试过的..像这样。

 AutoCompleteTextBoxSample.AutoCompleteTextbox kodeTxt = e.Control as AutoCompleteTextBoxSample.AutoCompleteTextbox;
                if (kodeTxt != null)
                {
                    kodeTxt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                    kodeTxt.AutoCompleteCustomSource = source;
                    kodeTxt.AutoCompleteSource = AutoCompleteSource.CustomSource;
                }

then my autocomplete is not working anymore 然后我的自动填充功能不再起作用

What i want is just like this. 我想要的就是这样。

在此处输入图片说明

I would use Template Fields for this as described here: https://msdn.microsoft.com/en-us/library/bb288032.aspx 我将使用模板字段,如此处所述: https : //msdn.microsoft.com/zh-cn/library/bb288032.aspx

One of the Template Fields will be your custom control. 模板字段之一将是您的自定义控件。

This will involve writing code, rather than using the GUI. 这将涉及编写代码,而不是使用GUI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM