473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Responding to DataGrid selection

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?
Jul 26 '07 #1
2 1240
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:
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?
Jul 27 '07 #2
On Fri, 27 Jul 2007 00:02:02 +0200, Patrick <pa**@reply.newsgroup.msn.comwrote:
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]
Jul 27 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
6
by: BBFrost | last post by:
I'm using Net 1.1 (2003) SP1 & Windows 2000 Here's the issue ... Rows 12 thru 24 are selected in a datagrid. The user now unselects rows 12 thru 24 and selects rows 45 thru 70 ??? How can...
0
by: MrNobody | last post by:
hey guys... I'm trying to make my DataGrid have selection behavior similar to WindowsExplorer, where I can hold CTRL to add rows to a multi-row selection. Thanks to someone else on this...
1
by: MrNobody | last post by:
Is it at all possible to override the default behavior of a DataGrid when the mouse is clicked on a row? I am having a problem where I am trying to select multiple rows in a DataGrid by...
6
by: Alpha | last post by:
I have several textboxes that I need to chang the text when the selection row is changed in a datagrid. I have the following code. This textbox displayes the initial selection but when I click on...
3
by: Zachary Hilbun | last post by:
I'm using a DataGrid control in a web form. I can display it using binding but when I click on any of the items there is no feedback that that row has been selected. I changed SelectedItemStyle...
5
by: I am Sam | last post by:
I have a rather complicated problem I need to sort out and wonder if anyone can assist me. The ingredients: Two DropDownList Controls One DataGrid Purpose of Page:
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.