Question

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

Was it helpful?

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top