How do I display data automatically from a selected datagridview row to a text box without declaring values for separate text boxes, just need the col

  • Thread starter Thread starter hi, i'm Duy Nguyen
  • Start date Start date
H

hi, i'm Duy Nguyen

Guest
This is my idea but it doesn't work

DataTable dt = new DataTable ();



dt.Columns.Add ("_ ID");
dt.Columns.Add ("_ Tên");
dt.Columns.Add ("_ Danh tên");

dt.Rows.Add ("0", "duy", "hungyen");
dt.Rows.Add ("1", "duy1", "hungyen1");
dt.Rows.Add ("2", "duy2", "hungyen2");
dt.Rows.Add ("3", "duy3", "hungyen3");
dt.Rows.Add ("4", "duy4", "hungyen4");
dt.Rows.Add ("5", "duy5", "hungyen5");
dt.Rows.Add ("6", "duy6", "hungyen6");

dữ liệuGridView1.



private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
int n = this.Controls.Count;
int n1 = dt.Rows.Count;
int n2 = dt.Columns.Count;
for (int i = 0; i <= n - 1; i ++)
{
for (int j = 0; j <= n1 - 1; j ++)
{
for (int k = 0; k <= n2 - 1; k ++)
if (this.Controls .Name == dt.Columns [k] .ColumnName)
{
this.Controls .Text = dataGridView1.Rows [j] .Cells [k] .Value .ToString ();
}
}
}
dataGridView1.DataSource = dt;

Continue reading...
 
Back
Top