Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Databinding a textbox to a cell
 

Databinding a textbox to a cell

I have a form with a series of groupBoxes . Each groupBox represents a station and contains various controls related to that station. Each station has a serial number associated with a device connected to that station (i.e. It's always changing). This serial number is stored in a database that holds all information relevant to that station.

Basically I want to be able to databind each serial number textBox to a particular cell in the database (there are other controls that this needs to be done to but I'm starting with the simplest). For example, for station 1, the serial number exists at
this->TBCalDataSet->stations[0][2]
I can set it manually by
this->st1BuckSer->Text = Convert::ToString(this->TBCalDataSet->stations[0][2]);
but when I get to the rest of the controls, it's well over 100 iterations of setting the properties. I can't really use a for loop because one of the controls is a check box and using a pointer, I can't change the checked status. If I have to, I can place it all in a separate function and call it when I need it, but I was hoping that there would be a simpler way. I also think it would be spending a lot of time in that function.

So can I databind a textBox to a cell in a dataset... or even array (dataset preferred)? Or should I do it manually?

Thanks in advance
ScubaS2  Friday, July 31, 2009 2:48 AM
Hi ScubaS2,

Sorry I am not clear with the meaning after read your post. Based on my understanding, you want to bind TextBox.Text property with a cell. That cell is a DataTable's Row[rowIndex][columnIndex], right?
If I misunderstood your meaning, please correct me.

A simple binding does support to bind these two instance, use the following code
DataTable^ dt = gcnew DataTable();
dt->Columns->Add("Column1");
dt->Rows->Add("Item1");
this->textBox1->DataBindings->Add("Text", dt->Rows[0][0], "");
But dt->Rows[0][0] is an object type, it doesn't implement INotifyPropertyChanged interface. Any change of the datasource won't displayed on the TextBox control. So that binding is of no meaning.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Monday, August 03, 2009 3:33 AM
What you stated is my aim, can it be done where the INotifyPropertyChanged is implemented? As in copied to an array or something or is just a short falling in .NET?
ScubaS2  Monday, August 10, 2009 8:16 AM

You can use google to search for other answers

Custom Search

More Threads

• how to set default value for a textbox?
• Update Image Column Using Datagridview
• Display data from XML and SQL Server in the same DataGridView
• DataGridViewTextBoxCell and custom events
• DataGridView - Reorder columns
• DataSet, BindingSource, BindingNavigator Correct Way to Insert a Row?
• Many row's color in DataGrid Window Form
• Sorting unbound comboboxcolumn in a datagridview ?
• Extremely Slow Population of a DataGridView
• print datagridview cell format