뭔가를 감독하고 있다고 생각합니다.C# Windowsform 업데이트 동적 생성 콤보 상자
동적으로이 코드 (나는 텍스트 상자와 같은 다른 컨트롤에 대한 동일한 작업을 수행 등, 라벨)와 몇 가지 선택 상자를 생성 내가 자동으로 제어하는 모든 값을 선택한 값을 설정하려는
private ComboBox addControlsComboBox(string Id, string TBName, int point_X, int point_Y, int SizeWidth, DataTable DT)
{
ComboBox combobox = new ComboBox();
combobox.Text = TBName;
combobox.Location = new Point(point_X, point_Y);
combobox.Size = new Size(SizeWidth, 20);
combobox.Name = Id + TBName;
combobox.DataSource = DT;
combobox.DisplayMember = "key";
combobox.ValueMember = "value";
combobox.Enabled = true;
return combobox;
}
ComboBox를 제외하고는 올바른 값으로 설정됩니다. 1 개의 comboBox가 업데이트되지 않지만 모든 ComboBox가 업데이트됩니다.
중첩 된 사전 개체를 사용하여 일치해야하는 모든 값을 저장합니다.
내가 뭘 잘못 사용 된 업데이트 코드
foreach (Control gb in GroupPanel.Controls)
{
foreach (Control childc in gb.Controls)
{
if (DataCollection[GroupNames].ContainsKey(childc.Name))
{
KeyName = childc.Name;
numberLessKeyName = SL.RemoveDigits(childc.Name);
TextValue = DataCollection[GroupNames][KeyName];
switch (NumberLessKeyName)
{
case "Name":
int IntTextValue = Convert.ToInt32(TextValue);
TextValue = IntTextValue.ToString("d2");
break;
}
switch (childc.GetType().ToString())
{
case "System.Windows.Forms.TextBox":
childc.Text = TextValue;
break;
case "System.Windows.Forms.ComboBox":
// Not Working
ComboBox combobox = (ComboBox)childc;
combobox.SelectedValue = TextValue;
//Also not Working
// --> childc.Text = TextValue;
break;
case "System.Windows.Forms.CheckBox":
CheckBox chChildc = (CheckBox)childc;
if (TextValue == "Yes")
{
chChildc.Checked = true;
}
break;
};
}
}
}
의 일부를 참조하십시오?
누군가 제발 나를 도와 줄 수 있습니까?
[편집 1] 카롤
에
덕분에 나는 다음과 같은 라인 +가 ICloneable 인터페이스를 추가하고 일했다. 많은 감사. 검색 사람들을 위해
DataTable DT = new DataTable();
DT = DTAttribute;
DataTable DTClone = (DataTable)DT.Clone();
[C# 개체 클론 전쟁] [1] link
[수정 2] 다른 아이디어는 (또한 작동)
DataTable DT = new DataTable();
DT = DTAttribute;
DataTable DTClone = DT.Copy();
업데이트 할 콤보 상자를 선택하는 조건은 무엇입니까? –
왜이 태그는'[wpf]'입니까? –