런타임에 사용자가 선택할 수있는 확인란의 수를 모르는 경우 어떻게 문자열 배열에 동적으로 생성 된 확인란의 이름을 저장할 수 있습니까? 10 개의 동적 체크 박스와 10 개의 사용자 중 6 개의 체크 박스를 무작위로 선택했다고 가정 해 봅시다. 이제 선택한 체크 박스의 이름을 가져 와서 문자열 배열에 저장할 수 있습니다.동적 배열의 이름을 문자열 배열에 저장하는 방법
동적 인 이벤트 상자에서 이벤트 처리기를 사용하는 방법을 알고 있지만 배열의 크기가 무엇인지 모르는 경우 Straing 배열을 선언하는 방법을 혼동합니다. 여기
나는 지금까지 무엇을했는지 -
가private void CheckBoxCheckedChanged(object sender, EventArgs e)
{
CheckBox c = (CheckBox)sender;
//Label myLabel;
String str = null;
if (c.Checked == true)
{
str = c.Text;
gpBox[gpcount] = new GroupBox();
gpBox[gpcount].Name = "gpBox" + Convert.ToString(count);
gpBox[gpcount].Text = str;
gpBox[gpcount].Location = new Point(5, gpposition);
gpBox[gpcount].AutoSize = true;
this.Controls.Add(gpBox[gpcount]);
aCommand3 = new OleDbCommand("select * from batch_tbl where batch_branch LIKE '" + str + "'", main_connection);
aAdapter3 = new OleDbDataAdapter(aCommand3);
ds3 = new DataSet();
aAdapter3.Fill(ds3, "app_info");
ds3.Tables[0].Constraints.Add("pk_bno", ds3.Tables[0].Columns[0], true);
int batch_count = ds3.Tables[0].Rows.Count;
batchCheckBox = new CheckBox[batch_count];
//filling the groupbox with batch code by generating dynamic checkboxes
for (int j=0; j < batch_count; ++j)
{
batchCheckBox[j] = new CheckBox();
batchCheckBox[j].Name = "batch" + Convert.ToString(k);
batchCheckBox[j].Text = ds3.Tables[0].Rows[j][1].ToString();
Console.WriteLine(batchCheckBox[j].Text);
batchCheckBox[j].Location = new System.Drawing.Point(104 * position, 30);
gpBox[gpcount].Controls.Add(batchCheckBox[j]);
batchCheckBox[j].CheckStateChanged += new System.EventHandler(BatchBoxCheckedChanged);
position++;
count++;
Console.WriteLine(batchCheckBox[j].Name);
k++;
}
position = 1;
gpposition += 100;
}
else
{
count--;
this.Controls.RemoveByKey("lbl" + c.Name);
this.Update();
}
}
int total_batch = 1;
string[] batchname;
private void BatchBoxCheckedChanged(object sender, EventArgs e)
{
CheckBox batchBox = (CheckBox)sender;
//Here I want to store name of checkbox in array
if (batchBox.Checked == true)
{
batchname = new String[total_batch];
total_batch++;
}
else
{
}
}
을 완료한다
everbody 주셔서 감사합니다. 배열 대신에'List names = new List ()' –
Sachin
@ Sachine gor 안내를 부탁드립니다. 목록을 새로 사용할 수 있도록 목록을 사용할 수 있도록 몇 가지 주요 사항을 알려주십시오. Furthur이 이름을 다른 형식으로 전달해야합니다. – user2241865
@ user2241865 목록은 기본적으로 크기 (용량)가 동적으로 조정될 수있는 배열입니다. 대부분의 시나리오에서 작업하는 것이 더 쉽습니다. –