Hello, i have written some code, which fills controls with some data from a database. Everything works fine if controls are put directly in a window. But how to fill controls, which are inside other controls, such as TabControls, GroupBoxes etc. My code looks like this:
Some window:
private void LoadDataP()
{
if (ID.Length > 0)
{
if (baseButtons.LoadProcedureSelectName != string.Empty)
LoadData = SqlHelper.GetTable(baseButtons.LoadProcedureSelectName, new string[] { IdName, ID });
if (LoadData != null)
foreach (DataRow dr in LoadData.Rows)
{
SqlHelper.FillWindowControllsWithData(myGrid, dr);
}
}
}
There are methods in another class.They do the main job:
public static void FillWindowControllsWithData(Grid windowGrid, DataRow dataRow)
{
foreach (Control ctrl in windowGrid.Children)
{
FillWindowControllsWithData(ctrl, dataRow);
}
}
public static void FillWindowControllsWithData(Control ctrl, DataRow dataRow)
{
if (ctrl.Name.IndexOf("db_") == 0)
{
if (ctrl is TextBox)
{
if (dataRow.Table.Columns.Contains(ctrl.Name.Substring(3)))
{
((TextBox)ctrl).Text = dataRow[ctrl.Name.Substring(3)].ToString();
}
}
} //end if
}
So does anybody know how to fill data in a texbox, which is in some groupbox or tabcontrol, which also have children..?