none
read datgridview data from another form RRS feed

  • Question

  • hello

    i have datagridview in form1

    and when i loop datagridview from form2 he says that no row(exit the loop)

    in form2 i make instance of form1

    form1 frm1 = new form1()

    and write:

    for each row in frm1.datagridview

    {

    {

    i decided to create constructor to form2 : argument is datagridview

    and when call form2 i pass the datagridview from form1

    but it isnt help too

    anyone have solution step by step(because i beginer c#)

    thanks


    oren t

    Thursday, October 23, 2014 12:12 PM

Answers

  • Don't try to do scripting style programming with C#. Separate your User Interface from the Data. How deep that goes is depending from your program, but use never the UI for Data.

    Success
    Cor

    Thursday, October 23, 2014 3:22 PM
  • Which form is instantiated first?

    Form1 or Form2.

    I would have thought form1 first and that instantiates form2.

    How are you getting your data for whichever form gets it originally?

    Do you go get it before you instantiate the second form?

    If not then there definitely won't be anything there when you read it.

    I would expect you to go get the data somehow, stick it in a collection of some sort and then bind your datagridview to that.

    Is that what you do?

    If so then pass that collection rather than the datagridview into the constructor.

    Show us some code.

    Thursday, October 23, 2014 3:25 PM
    Moderator

All replies

  • Hi Oren

    First you need to confirm,DataGridView in Form1 is Loaded with data when you read the DataGridView values


    Happy Coding, RDRaja

    Thursday, October 23, 2014 3:09 PM
  • Don't try to do scripting style programming with C#. Separate your User Interface from the Data. How deep that goes is depending from your program, but use never the UI for Data.

    Success
    Cor

    Thursday, October 23, 2014 3:22 PM
  • Which form is instantiated first?

    Form1 or Form2.

    I would have thought form1 first and that instantiates form2.

    How are you getting your data for whichever form gets it originally?

    Do you go get it before you instantiate the second form?

    If not then there definitely won't be anything there when you read it.

    I would expect you to go get the data somehow, stick it in a collection of some sort and then bind your datagridview to that.

    Is that what you do?

    If so then pass that collection rather than the datagridview into the constructor.

    Show us some code.

    Thursday, October 23, 2014 3:25 PM
    Moderator