Search code examples
c#telerik-grid

How to convert & insert string into List<int> at the same time?


I want to get some data out of telerik grid view and convert it's values(some cells) into List<int> (and some not)

i just want insert it into the list

foreach (int item in _MyAmount)
{
     _MyAmount.Select(int.Parse).ToList();
     radGridView1.CurrentRow.Cells[item].Value.ToString();
}

What should I do?


Solution

  • I think your foreach loop is bit iffy. From what you've described you want to run through every row in the telerik gridview (presumably radGridView1?), convert it to int and then save it in _MyAmount.

    If my assumptions are correct then you should use something like this:

    foreach (var Row in radGridView1.Rows)
    {
        foreach (var Cell in Row.Cells)
        {
            _MyAmount.Add((int) Cell.Value);
        }
    }
    

    This assumes there is more than 1 cell in each row. If not then you could shorten to:

    foreach (var Row in radGridView1.Rows)
    {
        _MyAmount.Add((int) Row.Cells[0].Value);
    }
    

    UPDATE

    For a RadGrid try this:

    foreach (var Row in radGridView1.Items)
    {
        _MyAmount.Add((int) Row["UniqueName"].Text);
    }
    

    UPDATE 2

    Seems a bit odd that it accepts 'Rows' as a collection on radGridView1 but then not '.Value' for the cell. I'm guessing a bit now, but what if you tried mixing the 2 like this:

    foreach (var Row in radGridView1.Rows)
    {
        _MyAmount.Add((int) Row["UniqueName"].Text);
    }