Search code examples
c#datagridviewgridcontrol

C# DevExpress GridControl Rows


I wanna know how I can transform this to GridControl code instead of DataGridView.

foreach (DataGridViewRow row in (IEnumerable)this.dataGridView1.Rows)
            {
                Data.SomethingA item = new Data.SomethingA
                {
                    item.ac = Convert.ToUInt32(row.Cells[5].Value.ToString())
                };
                item.ad = Convert.ToUInt32(row.Cells[2].Value.ToString()[7].ToString());
                item.ab = row.Cells[1].Value.ToString();
                item.az = row.Cells[3].Value.ToString();
                item.ae = Convert.ToUInt32(row.Cells[4].Value.ToString());
                item.aq = row.Cells[6].Value.ToString();
               ABC.Add(item);
            }

Thank you


Solution

  • I assume you're using DataTable as DataSource. Cast it back to DataTable and loop through rows of datatable

    private void DoSomething()
    {
        DataTable table = (DataTable)grid.DataSource;
        foreach (DataRow row in table.Rows)
        {
           Data.SomethingA item = new Data.SomethingA
           {
               item.ac = Convert.ToUInt32(row[5].ToString())
           };
           item.ad = Convert.ToUInt32(row[2].ToString()[7].ToString());
           item.ab = row[1].ToString();
           item.az = row[3].ToString();
           item.ae = Convert.ToUInt32(row[4].ToString());
           item.aq = row[6].ToString();
           ABC.Add(item);
        }
    }