Acces textbox from another form
Hello :) I have two forms and i want to acces in the main form a textbox which is placed in the second form..but the textbox isn't visible for the main form. how can i do that? thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Mar 20, 2013, 2:06 PM EDT
VulpesRank #55 · 29.2K reputationPosted Mar 16, 2013, 5:25 AM EDT
mos martin7 reputationPosted Mar 16, 2013, 9:49 AM EDT
i really appreciate your help..
VulpesRank #55 · 29.2K reputationPosted Mar 16, 2013, 12:38 PM EDT
Try this instead:
private void pictureBox1_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = "..";
conn.Open();
Acasa main = (Acasa)Application.OpenForms["Acasa"];
DataGridView dgv = main.clientGridView;
int i = dgv.CurrentRow.Index;
int maxRows = dgv.Rows.Count;
if (i != maxRows - 1)
{
i++;
textBox1.Text = dgv.Rows[i].Cells[0].Value.ToString();
textBox2.Text = dgv.Rows[i].Cells[1].Value.ToString();
textBox3.Text = dgv.Rows[i].Cells[2].Value.ToString();
textBox4.Text = dgv.Rows[i].Cells[3].Value.ToString();
textBox5.Text = dgv.Rows[i].Cells[4].Value.ToString();
dgv.Rows[i].Selected = true;
dgv.Rows[i -1].Selected = false; // make sure only a single row is selected
}
else
{
MessageBox.Show("..");
}
conn.Close(); // move this to the end so you always close the connection
}
mos martin7 reputationPosted Mar 17, 2013, 5:31 AM EDT
for example in the datagrid i have
1
2
3
4
5
if my selected row is 3, click next and record no 4 is shown, but when i click next again doesn't show 5, it's still 4.
VulpesRank #55 · 29.2K reputationPosted Mar 17, 2013, 9:07 AM EDT
mos martin7 reputationPosted Mar 17, 2013, 9:11 AM EDT
Violeta Popa132 reputationPosted Mar 20, 2013, 12:47 PM EDT
but i keep getting this error for the bolded line and i can't understand why
"Object reference not set to an instance of an object."