Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get datagridview selected row value to textbox,radiobutton and dropdownlist which is in another windows form c# for up date

getting this error(Object reference not set to an instance of an object.)


this is my form1 code
--------------------------
public static string Gender, Division, Genre, Event, Scoreeve, Relay,Note,Selectmode;
public static int Rounds, Scoreteam, timeprecison, Advancement




public frmAddEditEvents()
{
if (Selectmode == "update")
fillRecord();
if (Selectmode == "insert")
InitializeComponent();


}


public void fillRecord()
{



rdbMale.Text = Gender;
cmbDivison.Text = Division;
rdbRun.Text = Genre;
cmbEvent.Text = Event;
chkScore.Text = Scoreeve;
chkRelay.Text = Relay;
nudRounds.Value = Rounds;
nudScores.Value = Scoreteam;
nudTimeprecision.Value = timeprecison;
txtEventnote.Text = Note;
numericUpDown1.Value = Advancement;
btnSave.Text = "update";
}

this is form 2
-------------------------


private void tsbtnEdit_Click(object sender, EventArgs e)
{


if (grdEvents.SelectedRows.Count > 0)
{



frmAddEditEvents.Selectmode = "update";

frmAddEditEvents.Gender = Convert.ToString(grdEvents.SelectedRows[0].Cells[1].Value);

frmAddEditEvents.Division = Convert.ToString(grdEvents.SelectedRows[0].Cells[2].Value);
frmAddEditEvents.Genre = Convert.ToString(grdEvents.SelectedRows[0].Cells[3].Value);
frmAddEditEvents.Event = Convert.ToString(grdEvents.SelectedRows[0].Cells[4].Value);
frmAddEditEvents.Scoreeve = Convert.ToString(grdEvents.SelectedRows[0].Cells[5].Value);
frmAddEditEvents.Relay = Convert.ToString(grdEvents.SelectedRows[0].Cells[6].Value);
frmAddEditEvents.Rounds = Convert.ToInt16(grdEvents.SelectedRows[0].Cells[7].Value);
frmAddEditEvents.Scoreteam = Convert.ToInt16(grdEvents.SelectedRows[0].Cells[8].Value);
frmAddEditEvents.timeprecison = Convert.ToInt16(grdEvents.SelectedRows[0].Cells[9].Value);
frmAddEditEvents.Note = Convert.ToString(grdEvents.SelectedRows[0].Cells[10].Value);
frmAddEditEvents.Advancement = Convert.ToInt16(grdEvents.SelectedRows[0].Cells[11].Value);
frmAddEditEvents obj = new frmAddEditEvents();
obj.ShowDialog();

return;


}
else
{
MessageBox.Show("Please select any record to update");
}

}
Posted

1 solution

Are your all controls accessable to another page? I think not, becouse all controls are private by default. so you need to set the properties of your all controls as public then try to access it.

hope it will work.
 
Share this answer
 
Comments
rockpune 7-Jul-12 2:04am    
ok i will try
rockpune 7-Jul-12 2:06am    
still it is getting error sir
Raje_ 7-Jul-12 2:14am    
check this link it will help you...
http://www.codeproject.com/Questions/146927/pass-gridview-selected-row-value-to-text-box-which

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