Hello friends,
I have created a datagridview at runtime using the createdatagrid() function passing some values and created the keypress event of that datagridview.
In that keypress event I set the selected row to the textbox when user presses the enter key i.e 13.
The above mentioned functionality works fine.
Now I want to make it at class level.
For e.g. I want to pass the textbox5 value to the createdatagrid() or filldata and then display the result back to the textbox5.
Note: I have successfully passed other values but I don't understand how to pass the value of textbox5 and how should I take the result back from function.
Following is the code
Please help me.
Thank you.
public void createdatagrid(int left,int top,int width,int height,)
{
dgvnew = new DataGridView();
dgvnew.Left = left;
dgvnew.Top = top;
dgvnew.Size = new System.Drawing.Size(width,height);
dgvnew.ReadOnly = true;
dgvnew.RowHeadersWidth = 5;
dgvnew.ScrollBars = ScrollBars.Vertical;
this.Controls.Add(dgvnew);
dgvnew.KeyPress += new KeyPressEventHandler(dgvnew_KeyPress);
}
public void filldata(string spname)
{
dsdgv = new DataSet();
dsdgv = clsobj.getDataset(spname);
dgvnew.DataSource = dsdgv.Tables[0];
dgvnew.AutoSize = false;
for (int i = 0; i < dsdgv.Tables[0].Rows.Count - 1; i++)
dgvnew.AutoResizeColumn(i);
dgvnew.Show();
}
void dgvnew_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
textBox5.Text = dgvnew.Rows[dgvnew.CurrentRow.Index - 1].Cells[0].Value.ToString();
dgvnew.Hide();
}
}
private void textBox5_TextChanged_1(object sender, EventArgs e)
{
createdatagrid(550, 172, 300, 200);
filldata("SP_PC");
}
[EDIT] Edited for grammar and spelling [/EDIT]