none
take value from DataGridViewRow RRS feed

  • Question

  • I trying to get datagridvalues like below, But it didnt work.  

    foreach (DataGridViewRow  msgRow in productDataGridView.Rows)
                {
                    int id = int.Parse(msgRow.Cells[0].Value.ToString());

    }

    Is there any other way to do that

    lakmal

    Sunday, March 11, 2012 6:13 AM

Answers

  • Hi, 

    Syntax you are using have no issues, this should work as it is

    msgRow.Cells[0].Value

    are you receiving any exception? probably this could be the reason because of  1. No value in cell  2. Non int value in cell

    you can also access value of cell with  

    productDataGridView[0][0].Value

    Hope this helps you....


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    Sunday, March 11, 2012 1:55 PM

All replies

  • Hi, 

    Syntax you are using have no issues, this should work as it is

    msgRow.Cells[0].Value

    are you receiving any exception? probably this could be the reason because of  1. No value in cell  2. Non int value in cell

    you can also access value of cell with  

    productDataGridView[0][0].Value

    Hope this helps you....


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    Sunday, March 11, 2012 1:55 PM
  • Hi Galgodage,

    Welcome to MSDN Forum.

    The code is correct, and @Kris444's code can also retrieve the data. You said it doesn't work, could you please what happened when you execute the code you posted? Is there an exception message been thrown, or the data are wrong?

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, March 14, 2012 3:26 AM
    Moderator
  • Hi Galgodage,

    Have you solved the issue? I look forward to hearing from you.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 19, 2012 2:20 AM
    Moderator