简体   繁体   English

如何通过单击按钮从DataTable在DevExpress Gridview中添加新行

[英]How to add new Row in DevExpress Gridview from DataTable on Button Click

I am new to C# and trying to know more by trying to develop simple Windows application. 我是C#的新手,并尝试通过开发简单的Windows应用程序来了解更多信息。 In the application i used the DevExpress GridView. 在应用程序中,我使用了DevExpress GridView。 i am trying to add the content of textbox control to DevExpress Unbounded Gridview on button click like this. 我试图像这样在按钮单击上将文本框控件的内容添加到DevExpress Unbounded Gridview中。 I tried like this but nothing show up in the GridView. 我这样尝试过,但是GridView中什么都没有显示。

Private void btn_Add_to_List_Click(object sender, EventArgs e)
    {            
        gridView1.AddNewRow();
    }

private void gridView1_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
    {
        DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView;
        view.SetRowCellValue(e.RowHandle, view.Columns[0], cBox_ProcessingMaterial.Text.ToString());
        view.SetRowCellValue(e.RowHandle, view.Columns[1], txtBox_Qty_Used.Text.ToString());


    }

This is the form i used 这是我使用的表格

The version of DevExpress i am using is 16.2.4. 我正在使用的DevExpress版本是16.2.4。 i have seen the documentation but the only thing i get is for bounded GridView only. 我看过文档,但是我得到的唯一是仅限于有界GridView。 please i need help. 请我需要帮助。 Thanks!! 谢谢!!

When you call AddNewRow it will fire an event - InitNewRow. 当您调用AddNewRow时,它将触发一个事件-InitNewRow。 In there you can initialise the values of the new row. 您可以在其中初始化新行的值。

This appears to be covered in their documentation: https://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridViewsBaseColumnView_InitNewRowtopic 这似乎在其文档中进行了介绍: https : //documentation.devexpress.com/#WindowsForms/DevExpressXtraGridViewsBaseColumnView_InitNewRowtopic

It includes an example, which is: 它包含一个示例,它是:

private void gridView1_InitNewRow(object sender, InitNewRowEventArgs e) {
   DevExpress.XtraGrid.Views.Grid.GridView view = sender as Grid.GridView;
   view.SetRowCellValue(e.RowHandle, view.Columns["PurchaseDate"], DateTime.Today);
}

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

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