【问题标题】:how to use buttonedit in devexpress gridcontrol如何在 devexpress gridcontrol 中使用 buttonedit
【发布时间】:2014-11-22 00:12:02
【问题描述】:

我正在尝试在其中一列中创建一个带有 buttonedit 的网格控件。当用户单击按钮编辑时,它会弹出一个表单来选择产品。在弹出窗口上完成选择后,它将选择中的 DataRow 返回到主网格,如下所示。

但是当列失去焦点时,我写入列的值消失了。

这是我的代码,它创建了 gridcontrol 的数据和 buttonedit 的点击事件。

    private void FrmSiparisNew_Load(object sender, EventArgs e)
    {
        dt = new DataTable();
        dt.Columns.Add("MALZEME_KODU",typeof(string));
        dt.Columns.Add("MALZEME_ACIKLAMA", typeof(string));
        dt.Columns.Add("ADET", typeof(decimal));
        dt.Columns.Add("BIRIM", typeof(string));
        dt.Columns.Add("FIYAT", typeof(decimal));
        dt.Columns.Add("KUR", typeof(string));
        dt.Columns.Add("TUTAR", typeof(decimal));
        DataRow dr = dt.NewRow();
        dt.Rows.Add(dr);

        gc.DataSource = dt;
    }

    private void repositoryItemButtonEditMalzemeKodu_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
    {
        FrmProducts frm = new FrmProducts(dt_products);
        frm.ShowDialog();

        DataRow dr_return = frm.dr;

        ButtonEdit buttonEdit = (sender as ButtonEdit);
        buttonEdit.Text = dr_return["URUNKOD"].ToString();

    }

为什么值会消失?我应该先填写数据表并再次绑定吗?我该如何解决这个问题?

【问题讨论】:

  • 就像toddmo说的,需要更新底层数据源dt,然后使用gc.RefreshDatasource()。可能没有必要更新 ButtonEdit 控件。 (dt 真的只有一行吗?如果没有,您可以从 e.RowNumber 或类似的东西中确定要更新的正确行 - 现在我面前没有类似的程序。)

标签: c# winforms gridview devexpress


【解决方案1】:

看起来按钮编辑与托管网格没有紧密连接。查看是否可以将该值分配给基础网格单元格或数据表行值。然后,它应该会粘住。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多