Ticket T195251
Visible to All Users

Grid - Adding a new row without assigned data source

created 10 years ago

hi,

i want add new rows in devexpress.

in C# girdView : gridview=dtg

C#
dtg.Rows.Add(); dtg.Rows[0].Cells[0].Value = Properties.Resources.background; dtg.Rows[0].Cells[1].Value = "Chi"; dtg.Rows[0].Cells[2].Value = "chon";

in Devexpress :

C#
private void ShowGrid(DataTable dt) { for (int i = 0; i < dt.Rows.Count; i++) { object[] obj = dt.Rows[i].ItemArray; gridView1.AddNewRow(); gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[0], obj[0].ToString()); gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[1], obj[1].ToString()); gridView1.UpdateCurrentRow(); } }

but devexpress no Result

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

Hello,

To use the GridView.AddNewRow method, you need to have a data source assigned to the grid.
If your task is to use the grid without the data source, you should add unbound columns to the grid and handle the GridView.CustomUnboundColumnData event. Learn more about it - Unbound Columns.
The grid can't operate without a data source. However, you're able to create an empty DataTable (without rows) that has only columns. Look at the following code:

C#
DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(int)); dt.Columns.Add("Name", typeof(string)); gridControl1.DataSource = dt;

Let me know if you have any further questions.

    Show previous comments (2)
    DevExpress Support Team 10 years ago

      [Posted by ki chon]

      [C#]But I am writing this, I have the following code in the form load.

      [C#]create table, but display emty result.

        Thanks.
        My problem was solved.

        DevExpress Support Team 10 years ago

          I'm happy to hear that you've found a solution.
          If you have further questions, let me know.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.