none
index out of range RRS feed

  • Question

  • Dear all,

                I have a datagridview which contains many rows with two columns, but the following return index was out range

               _MyString = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();

              Please suggest. Thanks.


    hon123456
    Monday, January 3, 2011 9:23 AM

Answers

  • Please make sure that atleast one row is selected before using SelectedRows[0].

    A check like if(dataGridView1.SelectedRows.Count > 0) would be helpful.

     

    If the problem still persists, add a break point and check where exactly (Rows / Cells) it goes wrong!


    Happy New Year 2011
    Please Mark as Answered If this answers your question Or UnMark as Answered if it did not.
    Happy to Help :)
    My Blog
    • Proposed as answer by zbarriver Monday, January 3, 2011 11:05 AM
    • Marked as answer by Mio_Miao Monday, January 10, 2011 6:36 AM
    Monday, January 3, 2011 9:27 AM