binding a TextBox to a column in a dataGrid

Hy I'm using C# and sqlConnection and i'm new in C# and .Net
I have 2 tables whith 2 dataAdaptors, a dataSet which is connected to the tables, 2 dataViews, and a dataGrid, a textBox in a Form
I bind the Text property of a textBox to a column in a dataSet from the design mode

I have he following problems:

1) When i make changes to the textBox nothing hapens in the dataGrid, how can i make changes to a dataSet...
2) When i select another row the textBox doesn't change acordingly

sorry for my bad english...
Thanks...Smile

[608 byte] By [jonDow] at [2007-12-16]
# 1

I'm not sure how you are setting up DataBinding but you don't need to create DataViews as this is done automatically by the data binding engine.

The best way to get this working is to use the designer and make sure you bind your DataGrid and TextBox in the same way. To do this, try the following:

Set DataGrid.DataSource to "YourDataSet" (do _not_ select "YourDataSet.YourTable").
Set DataGrid.DataMember to "YourTable".

DataBind the TextBox to a column in "YourTable".

This will ensure your TextBox and DataGrid are bound through the same "CurrencyManager" (the Windows Forms component that keeps different data bound controls in sync).

Joe Stegman
The Windows Forms Team
Microsoft Corp.

This posting is provided "AS IS" with no warranties, and confers no rights.

JoeStegman at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2
Thanks :) it worked....
I have another question:
I have a comboBox and I try to bind it with a column in a table in design time....
what i've done is:
- set the comboBox.DataSource = dataSet11.myTable
- comboBox.ValueMember = Field
- comboBox.DisplayMember = Field
- in the dataBindings area I set the:
- SelectedValue = dataSet11 - elev.tara
- SelectedItem = dataSet11 - elev.tara
the dataGrid is bound in the way you indicated previously
When I fill the dataAdapter it works fine: the comboBox shows the values from the specified field in the dropDown and the correct value is selected, but when a select another row it shows in the previous selected row System.Data.DataRowView and in the comboBox as well.
Another problem is that I want to display only unique values from the field... that filed reprezents the country of a student
I thank you ...
jonDow at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3
hy I've solved the problem i've connected the dataGrid.dataSource = dataSet.Mytable and it works fine..... but now i have another problem ....
what i want to do is this: i have a table with students and one column is their country, i want a comboBox that displays all the distinct countries found in tha table and when i select a row to be possible to change the country of that row from the comboBox...
As a bonus if it is possible to add a new country in the comboBox it will be perfect...
Is that possible to do only in the design (or in a simple way - a few lines of code) ?
thanks again....
jonDow at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...