HighTechTalks DotNet Forums  

Responding to DataGrid selection

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss Responding to DataGrid selection in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
=?Utf-8?B?UGF0cmljaw==?=
 
Posts: n/a

Default Responding to DataGrid selection - 07-26-2007 , 06:02 PM






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?

Reply With Quote
  #2  
Old   
=?Utf-8?B?TWFuaXNoIEJhZm5h?=
 
Posts: n/a

Default RE: Responding to DataGrid selection - 07-26-2007 , 11:04 PM






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...ding%20FAQ.doc
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



"Patrick" wrote:

Quote:
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?

Reply With Quote
  #3  
Old   
Morten Wennevik [C# MVP]
 
Posts: n/a

Default Re: Responding to DataGrid selection - 07-27-2007 , 03:49 AM



On Fri, 27 Jul 2007 00:02:02 +0200, Patrick <patl (AT) reply (DOT) newsgroup.msn.com> wrote:

Quote:
With a .Net 2's WinForms which contain
1) a DataGrid which is assigned to a DataSet's DataTable (some columnsare
"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?

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 = new DataGridView();
TextBox textBox1 = new TextBox();

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

DataSet set = 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 = set.Tables[0].NewRow();
row["ID"] = 1;
row["Value"] = "One";
set.Tables[0].Rows.Add(row);
row = set.Tables[0].NewRow();
row["ID"] = 2;
row["Value"] = "Two";
set.Tables[0].Rows.Add(row);
row = set.Tables[0].NewRow();
row["ID"] = 3;
row["Value"] = "Three";
set.Tables[0].Rows.Add(row);

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

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


--
Happy coding!
Morten Wennevik [C# MVP]


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.