简体   繁体   中英

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

You can just set the AspxGridView.DataSource = to dataGridView1.DataSource, or even better just set the AspxGrid.DataSource to be whatever your underlying datasource is (DataTable etc.).

The AspxGrid has a property to Auto generate the columns from the datasource.

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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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