Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am trying to retrieve selected row values retrieve another form textboxs

but i try not getting any one tell me how can i do this

from1
C#
public static string abc, xyz;

     private void from1_Load(object sender, EventArgs e)
     {
         abc = txtTeamname.Text;
         xyz = txtAbbrivation.Text;
     }

form2
C#
 DataGridViewRow row = grdTeams.Rows[e.RowIndex];
 from1  TAE = new from1();
 from1.abc = row.Cells[0].Value.ToString();
 from1.xyz = row.Cells[1].Value.ToString();

TAE.ShowDilog();


it showing the form but not showing values into textboxes
Posted
Updated 13-Jul-12 22:43pm
v2

1 solution

There are a couple of problems here:

Firstly, don't expose your fields - use properties instead. That allows you to control how and when external objects can access your form - using fields directly locks the design of your form because the outside world could play with your fields at any time.

Secondly, when you load your form, you are overwriting any values you set before you called the ShowDialog method in the parent form.

Thirdly, you shouldn't use static variables here - you really neither want nor need them - use class instance variables instead.

How I would do it:
C#
public class Form1
   {
   public string Abc
      {
      get { return txtTeamname.Text; }
      set { txtTeamname.Text = value; }
      }
   }


In form 2:

C#
DataGridViewRow row = grdTeams.Rows[e.RowIndex];
Form1 TAE = new Form1();
TAE.Abc = row.Cells[0].Value.ToString();
TAE.ShowDialog();



Finally, stop using VS default names - don't call forms Form1, Form2 - use names which describe what they do. "OpenFileDialog" is a lot more meaningful than the VS default version "Form243" would have been...
 
Share this answer
 
Comments
rockpune 14-Jul-12 4:48am    
thnx sir

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