Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
1.00/5 (1 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


C#
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
C#
f.posteoffert.Text = annoncetb[0]["diplome"].ToString();

the debug corrupted and the message that i have is f form is null
Posted
Updated 26-Aug-19 0:25am
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 16-Aug-19 17:11pm    
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

I think annoncetb is not defined in the scope in which you try to use it.
 
Share this answer
 
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
i have two forms with the same name but not in the same directory, when i change the name of one of these forms; it works and the problem is clear

thanx
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900