Dong Lam Trien

Dong Lam Trien

  • 833
  • 986
  • 145.7k

Why can't I add a record to Devexpress's gridView?

Mar 23 2023 1:27 AM

I have the following code, when I run it, I can't add a new line to the gridView, thanks for your help:

for (int i = 0; i < dt.Rows.Count; i++)
{
    try
    {
        // Add into gridView
        gridView1.AddNewRow();

        // Set rowHandle
        int rowHandle = gridView1.GetRowHandle(gridView1.DataRowCount);
        if (gridView1.IsNewItemRow(rowHandle))
        {
            gridView1.SetRowCellValue(rowHandle, gridView1.Columns["ID"], i);
            gridView1.SetRowCellValue(rowHandle, gridView1.Columns["Name"], "Peter");
            gridView1.SetRowCellValue(rowHandle, gridView1.Columns["Age"], 35);

            // Update gridView
            gridView1.UpdateCurrentRow();
        }
        else
        {
            Debug.Print("Not row new!");
        }
    }
    catch (Exception ex)
    {
        Debug.Print("Exception ex: " + ex);
    }
}

 


Answers (8)