简体   繁体   中英

Create custom datagridview's Column type

i just create a custom control, i want this control implement to datagridview's column.

but how? is it possible?

在此处输入图片说明

for example, i want add my column type like "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

One of the Template Fields will be your custom control.

This will involve writing code, rather than using the GUI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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