question

OulcanAkca-9475 avatar image
0 Votes"
OulcanAkca-9475 asked ·

C# How can I do this ?

The TC I entered with tbxTC in the first form (it is a long number in Db), in dgwRules in the second form, I want to show the information with the TC I entered in the first form. In doing so, datas are not coming to dgwRules-although it happens-. It works fine when I do this thing the same another form. I think there is something I don't know. Can you help me?

-Form1-

 public void tbxTC_TextChanged(object sender, EventArgs e)
         {
    
             Ayarlar ayarlar = new Ayarlar();
               
             if (!String.IsNullOrEmpty(tbxTC.Text))
             {
                 ayarlar.dgwRules.DataSource = _iManagerPanelInformationService.GetManagerPanelInformationByTC(Convert.ToInt64(tbxTC.Text));
    
             }
             else
             {
                 ayarlar.idGetir();
             }
    
         }


-Ayarlar-

 public void idGetir()
         {
    
    
             dgwRules.DataSource = _iManagerPanelInformationService.GetAll();
    
         }
dotnet-csharpdotnet-entity-framework
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered ·

It seems that you should change the location of ayarlar variable:

 Ayarlar ayarlar = null; // <-- ADD THIS LINE
 public void tbxTC_TextChanged(object sender, EventArgs e)
 {
     // Ayarlar ayarlar = new Ayarlar(); <-- REMOVE THIS LINE
    . . .

Then initialise it. You probably already have a ‘new Form1()’ inside the Ayarlar form. Then add one line:

 . . .
 var f1 = new Form1();
 f1.ayarlar = this; // <-- ADD THIS LINE
 . . .

Or show details about the usage of these forms.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

'ayarlar' is returning null and, I'm getting an error but, When I organized the codes you suggested as follows, what I wanted was;

   . . .
     public Ayarlar ayarlar = new Ayarlar();
      public void tbxTC_TextChanged(object sender, EventArgs e)
      {
             
         . . .
      }
      . . .
      var f1 = new Form1();
      f1.ayarlar = this; // <-- ADD THIS LINE
      . . .
0 Votes 0 ·