C# 画面上のコントロールを判別して状態チェックする
テキスト、コンボ、DateTimePicker等の
種別に分けて状態をチェックするロジック
foreach (Control c in MainPanel.Controls)
{
if (c.GetType().Equals(typeof(TextBox)))
{
strNumber = (c.Name.Replace("txt_", ""));
switch (strNumber)
{
case "0":
c.Text = serviceCd.dataInfo.Syurui;
break;
case "1":
c.Text = serviceCd.dataInfo.Koumoku;
break;
case "2":
c.Text = serviceCd.dataInfo.ServiceName;
break;
default:
break;
}
}else if(c.GetType().Equals(typeof(ComboBox)))
{ // コンボボックス
ComboBox tmp = (ComboBox)c;
int index = 0;
if (c.Name == "cmbKoumoku")
{ // コンボボックス
if (Int32.TryParse(serviceCd.dataInfo.Koumoku, out index))
{
tmp.SelectedIndex = getComboIndex(tmp, index);
}
else
{
tmp.SelectedIndex = -1;
}
}else if (c.Name == "cmbSantei")
{
if (Int32.TryParse(serviceCd.dataInfo.SanteiId, out index))
{
tmp.SelectedIndex = getComboIndex(tmp, index);
}else
{
tmp.SelectedIndex = -1;
}
}
}else if (item.GetType().Equals(typeof(DateTimePicker)))
{
user.dataInfo.Birthday = item.Text.ToString();
}
}