如何改变DataGridViewComboBoxCell到DataGridViewTextBoxCell

本文关键字:DataGridViewComboBoxCell DataGridViewTextBoxCell 改变 何改变 | 更新日期: 2023-09-27 18:07:59

我试图改变一个单元格内的DataGridViewComboBoxColumn从DataGridViewComboBoxCell为DataGridViewTextBoxCell

这是我为了改变它而输入的行:

dataGridView1[0,3] = new DataGridViewTextBoxCell();

运行这行后,单元格仍保持其DataGridViewComboBoxCell类型。

提前感谢,Nadav

如何改变DataGridViewComboBoxCell到DataGridViewTextBoxCell

我看不出有什么问题。下面的表格创建了一个DataGridView,并提供了一个DataGridViewComboBoxColumn,其中asdfqweryxcv作为可能的组合。在FormLoad事件期间,网格由四行有效填充。然后执行您的代码行,它按预期执行。

我错过了什么吗?

代码如下:

public partial class Form1 : Form
{
    public Form1() { InitializeComponent(); }
    private void Form1_Load(object sender, EventArgs e)
    {
        dataGridView1.Rows.Add("asdf");
        dataGridView1.Rows.Add("qwer");
        dataGridView1.Rows.Add("yxcv");
        dataGridView1.Rows.Add("asdf");
        dataGridView1[0, 3] = new DataGridViewTextBoxCell();
    }
}

设计文件的代码:

partial class Form1
{
    /// <summary>
    /// Erforderliche Designervariable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;
    /// <summary>
    /// Verwendete Ressourcen bereinigen.
    /// </summary>
    /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
    #region Vom Windows Form-Designer generierter Code
    /// <summary>
    /// Erforderliche Methode für die Designerunterstützung.
    /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
    /// </summary>
    private void InitializeComponent()
    {
        this.dataGridView1 = new System.Windows.Forms.DataGridView();
        this.Column1 = new System.Windows.Forms.DataGridViewComboBoxColumn();
        ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
        this.SuspendLayout();
        // 
        // dataGridView1
        // 
        this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
        this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
        this.Column1});
        this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.dataGridView1.Location = new System.Drawing.Point(0, 0);
        this.dataGridView1.Name = "dataGridView1";
        this.dataGridView1.Size = new System.Drawing.Size(470, 262);
        this.dataGridView1.TabIndex = 0;
        // 
        // Column1
        // 
        this.Column1.HeaderText = "Column1";
        this.Column1.Items.AddRange(new object[] {
        "asdf",
        "qwer",
        "yxcv"});
        this.Column1.Name = "Column1";
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(470, 262);
        this.Controls.Add(this.dataGridView1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.Load += new System.EventHandler(this.Form1_Load);
        ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
        this.ResumeLayout(false);
    }
    #endregion
    private System.Windows.Forms.DataGridView dataGridView1;
    private System.Windows.Forms.DataGridViewComboBoxColumn Column1;
}
相关文章:
  • 没有找到相关文章