사용자가 항목을 선택할 수 있고 체크리스트 상자의 해당 항목을 기반으로 일부 다른 항목을 채워야하는 콤보 상자가 있습니다.
소스를 콤보 박스에 바인딩하는 데 사용되는 코드이지만이 경우에는 작동하지 않습니다.
comboBox1.ValueMember = "crane index";
comboBox1.DisplayMember = "crane type";
comboBox1.DataSource = test.Tables["cranemaintable"];
이것은 데이터베이스의 테이블
| Crane Index | Crane Model Number | Crane Type |
|:-----------:|:------------------:|:-----------:|
| 221 | LR 1400-1 | Crawler |
| 258 | CC 2800 | Crawler |
| 262 | CC 2400-1 | All Terrain |
| 265 | CC 6800 | Crawler |
| 277 | LR 11350 | All Terrain |
나와 관련된 다른 질문을 확인했지만 문제에 대한 답을 찾을 수 없습니다. 도움을 주시면 감사하겠습니다. 감사.
업데이트 : 이것이 제가 발견하고 저를 위해 일한 것입니다.
// create a list that holds all the crane types but it should not have duplicated items
List<string> crane_type = new List<string>();
for (int i = 0; i< test.Tables["cranemaintable"].Rows.Count; i++)
{
if (!crane_type.Contains(test.Tables["cranemaintable"].Rows[i]["crane type"]))
{
crane_type.Add(Convert.ToString(test.Tables["cranemaintable"].Rows[i]["crane type"]));
}
}
//bind the crane_type list to the combobox1
comboBox1.DataSource = crane_type;
좋아, 먼저 내 대답은 추악하지만 작동하고 내가 아는 유일한 것이므로 데이터베이스 테이프를 목록으로 가져 오는 것으로 시작합니다.이 클래스는 사용할 수 있습니다
public class myclass
{
public string CraneIndex { get; set; }
public string CraneModelNumber { get; set; }
public string CraneType { get; set; }
}
그리고 목록 3 개를 만드세요
List<myclass> myclasses = new List<myclass>();
List<myclass> myclasses1 = new List<myclass>();
List<myclass> myclasses2 = new List<myclass>();
여기에서 테이블을 목록으로 가져온 myclasses
다음 데이터베이스에서 가져온 기본 목록을 고유 한 유형 만 갖도록 필터링합니다.
myclasses1 = myclasses.GroupBy(myclass => myclass.CraneType).Select(x => x.First()).ToList();
comboBox1.DataSource = myclasses1;
comboBox1.DisplayMember = "CraneType";
속성으로 이동하여 combobox
구독하고 selectedindexchanged
이를 기능에 추가하십시오.
myclasses2.Clear();
foreach (var item in myclasses)
{
if (comboBox1.Text==item.CraneType)
{
myclasses2.Add(item);
}
}
checkedListBox1.Items.Clear();
foreach (var item in myclasses2)
{
checkedListBox1.Items.Add(item.CraneModelNumber);
}
this.checkedListBox1.DisplayMember = "cranemodels";
checkedListBox1.Refresh();
도움이나 설명이 더 필요하면 알려주세요.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다