How do I programmatically set the value of Windows Controls?

In the following online KB article:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;313482

Microsoft recommends:

"In general, do not use the user interface to change data programmatically. Instead, use the bound object (which is typically DataView) to change data."

The following sample code shows how you can get the current DataRowView from an MM .NET DataGrid and programmatically set associated text box values:

In C#:

// Get the grid's current DataRow
DataRowView DrView;
mmBusinessObject BusinessObject;
DrView = this.grdOrders.GetCurrentRow(out BusinessObject);

// Programmatically set the values
DrView["ShipName"] = "Greg Breeding";
DrView["ShipAddress"] = "102 Morningside Lane";
DrView["ShipCity"] = "Charlottesville";

// Rebind the user interface controls
this.BindControl(this.txtShipName);
this.BindControl(this.txtShipAddress);
this.BindControl(this.txtShipcity);

In VB .NET:

' Get the grid's current DataRow
Dim DrView As DataRowView
Dim BusinessObject As mmBusinessObject
DrView = Me.grdOrders.GetCurrentRow(BusinessObject)

' Programmatically set the values
DrView("ShipName") = "Greg  Breeding"
DrView("ShipAddress") = "102 Morningside Lane"
DrView("ShipCity") = "Charlottesville"

' Rebind the user interface controls
Me.BindControl(this.txtShipName)
Me.BindControl(this.txtShipAddress)
Me.BindControl(this.txtShipcity)

© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 03/11/10
Comment or report problem with topic