I have a datagrid, and i use to access its values like:
userName = frm_main.datagrid1.Item(1, 0).Value.ToString
however this thing is perfectly fine, but now i just created a new form and when i tried to access this Item property of datagrid1 its not available.
Does anyone have idea, whats the issue?
To be more precise when i am typing it shows me frm_main as highlighted like class in sky blue color.
If you’re trying to access frm_main from a different form, it has to have an instance of frm_main to work with. Without an existing instance of frm_main for it to work with, as far as that form is concerned frm_main doesn’t exist.
I’m guessing that you’re initializing that second form from somewhere within frm_main? If so, when you initialize it, do something like this:
And in the code for Form2, put in:
This gives it the existing instance of frm_main to work with and access to all of the controls within it. You would just refer to it as Main, or whatever variable name you would like to give it in code.
*edit:*I just realized this was for VB.Net, the VB code for this would be
and then create your own constructor for Form2
That should do it!