DevExpress GridControl,如何通过EditForm更改单元格值,但编辑器不是重点

时间:2018-11-16 03:38:42

标签: c# devexpress gridcontrol

我在自定义EditForm中有2个编辑器,当editor1文本更改时,editor2文本属性分配了相同的值。 代码处理了textbox1.TextChanged事件。 更改textBox1.Text时,更改textbox2.Text显示,但是当textBox2获取焦点时,文本消失。 如何通过EditForm更改单元格值,但Editor不在焦点,或者当我更改textBox2显示值时,如何发布到我的gridRow。

public partial class Form1 :Form {
    public Form1() {
        InitializeComponent();

        GridControl gridControl = new GridControl();
        GridView gridView = new GridView();
        gridControl.MainView = gridView;
        gridControl.Dock = DockStyle.Fill;
        gridControl.Parent = this;

        DataTable table = new DataTable();
        table.Columns.Add("FirstName", typeof(string));
        table.Columns.Add("LastNmae", typeof(string));

        gridControl.DataSource = table;

        gridView.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
        gridView.OptionsBehavior.EditingMode = GridEditingMode.EditFormInplace;
        gridView.OptionsEditForm.CustomEditFormLayout = new CustomEditForm();

        Controls.Add(gridControl);
    }
}

public class CustomEditForm : EditFormUserControl
{
    public CustomEditForm()
    {
        InitializeComponent();

        TextBox textBox1 = new TextBox();
        textBox1.Location = new System.Drawing.Point(26, 17);
        textBox1.Size = new System.Drawing.Size(100, 22);
        textBox1.TabIndex = 0;
        this.Controls.Add(textBox1);


        TextBox textBox2 = new TextBox();
        textBox2.Location = new System.Drawing.Point(26, 47);
        textBox2.Size = new System.Drawing.Size(100, 22);
        textBox2.TabIndex = 0;
        this.Controls.Add(textBox2);

        this.SetBoundFieldName(textBox1, "FirstName");
        this.SetBoundFieldName(textBox2, "LastName");

        textBox1.TextChanged += (s, e) =>
        {
            textBox2.Text = (s as TextBox).Text;
        };
    }

    private void InitializeComponent()
    {
        SuspendLayout();

        this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Name = "Editor";
        this.Size = new System.Drawing.Size(230, 148);
        this.ResumeLayout(false);
        this.PerformLayout();
    }
}

0 个答案:

没有答案