With a .Net 2's WinForms which contain
1) a DataGrid which is assigned to a DataSet's DataTable (some columns are
"hidden" on screen)
2) a few TextBox which are aligned to different fields within the same
DataTable

What event do I code for the .Net DataGrid such that the TextBoxes's value
are updated as different rows are selected?

RE: Responding to DataGrid selection by ManishBafna

ManishBafna
Thu Jul 26 22:04:02 CDT 2007

Hi,
You should be using a BindingSource. You bind your DataTable to the
BindingSource and then bind the BindingSource to the control.Then everything
will be automatically handled.For more details refer below link:
http://windowsclient.net/samples//Go%20To%20Market/Data%20Binding/DataBinding%20FAQ.doc
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



"Patrick" wrote:

> With a .Net 2's WinForms which contain
> 1) a DataGrid which is assigned to a DataSet's DataTable (some columns are
> "hidden" on screen)
> 2) a few TextBox which are aligned to different fields within the same
> DataTable
>
> What event do I code for the .Net DataGrid such that the TextBoxes's value
> are updated as different rows are selected?

Re: Responding to DataGrid selection by Morten

Morten
Fri Jul 27 02:49:42 CDT 2007

On Fri, 27 Jul 2007 00:02:02 +0200, Patrick <patl@reply.newsgroup.msn.co=
m> wrote:

> With a .Net 2's WinForms which contain
> 1) a DataGrid which is assigned to a DataSet's DataTable (some columns=
are
> "hidden" on screen)
> 2) a few TextBox which are aligned to different fields within the same=

> DataTable
>
> What event do I code for the .Net DataGrid such that the TextBoxes's v=
alue
> are updated as different rows are selected?
>

Hi Patrick,

Use DataBinding for this. Bind the Text property of the TextBox to the =
Column you want to display. The code below demonstrates how to do this.=


DataGridView dataGridView1 =3D new DataGridView();
TextBox textBox1 =3D new TextBox();

protected override void OnLoad(EventArgs e)
{
this.Controls.Add(dataGridView1);
this.Controls.Add(textBox1);
textBox1.Location =3D new Point(dataGridView1.Width + 5, 0);

DataSet set =3D new DataSet();
set.Tables.Add(new DataTable());
set.Tables[0].Columns.Add("ID", typeof(System.Int32));
set.Tables[0].Columns.Add("Value", typeof(System.String));
DataRow row =3D set.Tables[0].NewRow();
row["ID"] =3D 1;
row["Value"] =3D "One";
set.Tables[0].Rows.Add(row);
row =3D set.Tables[0].NewRow();
row["ID"] =3D 2;
row["Value"] =3D "Two";
set.Tables[0].Rows.Add(row);
row =3D set.Tables[0].NewRow();
row["ID"] =3D 3;
row["Value"] =3D "Three";
set.Tables[0].Rows.Add(row);

dataGridView1.DataSource =3D set.Tables[0];
dataGridView1.Columns[0].Visible =3D false;

textBox1.DataBindings.Add("Text", set.Tables[0], "ID");
}


-- =

Happy coding!
Morten Wennevik [C# MVP]