Click here to Skip to main content
14,268,557 members
Rate this:
Please Sign up or sign in to vote.
See more:
i m stacked with this pb in my code i want to change a label text value of an opned form from an other form

What I have tried:

the code in form2


Annonce.Form1 f = (Annonce.Form1)Application.OpenForms["Annonce.Form1 "];
            agence.employeurDataTable empldt = new agence.employeurDataTable();
            agence.annonceDataTable annoncetb = new agence.annonceDataTable();
            agenceTableAdapters.employeurTableAdapter empad = new agenceTableAdapters.employeurTableAdapter();
            agenceTableAdapters.annonceTableAdapter annonad = new agenceTableAdapters.annonceTableAdapter();
            empad.parnumins(empldt, radGridView5.SelectedRows[0].Cells[1].Value.ToString());
            annonad.Fillbyannonce(annoncetb, radGridView5.SelectedRows[0].Cells[0].Value.ToString());
            if (empldt.Count == 0)
                return;
            
     f.posteoffert.Text = annoncetb[0]["diplome"].ToString();
       f.employeur.Text=empldt[0]["NominationEntre"].ToString();
            f.nbr.Text = annoncetb[0]["nbr_poste"].ToString();

the pb is in when i want to change the text
f.posteoffert.Text = annoncetb[0]["diplome"].ToString();

the debug corrupted and the message that i have is f form is null
Posted
Updated 14-Aug-19 6:37am
v3
Comments
ZurdoDev 14-Aug-19 11:28am
   
Please spell out words. It's hard to understand what you are asking.
If the error says that f is null, then it is. I'm not sure what you want us to do. Why is it null?
Amar zaidi 4 days ago
   
i have a poor level in english, and i'll try to make it better
what i try to ask is :
when i want to chage a control (exp label text ) in an opned form,from an other form i use the instruction
Annonce.Form1 f = (Annonce.Form1)Application.OpenForms["Annonce.Form1 "]; where Annonce.Form1 is the form contain a label to change
then if try to change label (exp f.label1.text="test";) i have message indecate f is null;
i hope that help you to understand my problem and i hope that you can help me ??? thanx

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I think annoncetb is not defined in the scope in which you try to use it.
   
Comments
Amar zaidi 14-Aug-19 13:12pm
   
is a datatable and is defined, the pb is in the opned form Annonce.Form1 when i debbug i found it null

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100