-
December 3rd, 2009, 02:14 PM
#1
Bind a text box to DGV value?
Hi all. New to .Net, hope you can clarify.
I have a simple form that pulls some data into a DataGridView control.
private void btnFind_Click(object sender, EventArgs e)
{
MyDBObject m = new MyDBObject();
DataTable dt = m.GetRecords();
List<MyDBObject> MyDBObjectList = m.GetGenericListFromDataTable<MyDBObject>(dt);
object o = dgvRows.DataSource = MyDBObjectList ;
dgvRows.Refresh();
}
A clicked event on the DGV loads a private variable (_currentObject ) in my form class:
private void dgvRows_CellClick(object sender, DataGridViewCellEventArgs e)
{
MyDBObject m = dgvRows.Rows[e.RowIndex].DataBoundItem as MyDBObject;
_currentObject = m;
}
I have a textbox elsewhere on the form that I wish to set to the value of one of the columns from the selected row (which is now tranferred to the private memvar).
In the form load event, I am trying:
textBox1.DataBindings.Add("Text", _currentObject , "desiredColumn");
This compiles and executes, but I never see the data in the textbox. Is this because MyDBObject is not a collection that inplements IList?
Is there an easy way to do this binding without direct assignments of DGV values to the text box at each clicked event?
Tnx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|