user3091970
user3091970

Reputation: 315

DevExpress GridView | DataGridView

I want to do the following but using GridView of DevExpress , how Can I do that please ?

List<RCDATA_INDEX> somethings = new List<RCDATA_INDEX>();

foreach (DataGridViewRow row in (IEnumerable)this.dataGridView1.Rows)
{
    AZ.RCDATA_INDEX items = new AZ.RCDATA_INDEX
    {
        datasize = Convert.ToUInt32(row.Cells[5].Value.ToString())
    };
    item.filenum = Convert.ToUInt32(row.Cells[2].Value.ToString()[7].ToString());
    item.hash = row.Cells[1].Value.ToString();
    item.realname = row.Cells[3].Value.ToString();
    item.offset = Convert.ToUInt32(row.Cells[4].Value.ToString());
    item.new_value = row.Cells[6].Value.ToString();
    somethings.Add(items);
}

Upvotes: 0

Views: 1817

Answers (2)

temmyraharjo
temmyraharjo

Reputation: 76

I would prefer using BindingSource and bind it into Gridview. After that if you want to making manipulation of your data. You just need to call like this :

List<RCDATA_INDEX> somethings = new List<RCDATA_INDEX>();
var Result = RCDataBS.Cast<RCDATA_INDEX>();
somethings.AddRange(Result);

It would be much easier using this code and you don't need to spend your resource to convert all the data into your model.

Upvotes: 0

DmitryG
DmitryG

Reputation: 17850

You can traverse through all the data rows within a GridView one-by-one, using the following approach:

// Obtain the number of data rows. 
int dataRowCount = gridView.DataRowCount;
// Traverse data rows  
for (int i = 0; i < dataRowCount; i++) {
    object cellValue = gridView.GetRowCellValue(i, "... specify field name here ...");
    // do something with cell Value

}

Please refer the Traversing Rows and Obtaining and Setting Cell Values help-articles to learn more;

Upvotes: 1

Related Questions