인 경우 콤보 선택한 색인을 설정할 수 없습니다. 드롭 다운을 드롭 다운으로 설정하여 데이터 바인딩 된 콤보 상자가있는 양식을 사용하므로 사용자가 콤보 상자에 입력 할 수 있습니다.사용자 유형이
내 문제는 사용자가 콤보 상자에 입력 할 때 입력 된 값 중 하나가 콤보 상자에 바인딩 된 값 중 하나와 일치하면 선택한 인덱스를 변경하지 않는다는 것입니다. 대신에 선택된 인덱스를 -1로 설정합니다 (따라서 선택된 값은 null입니다).
아무도 도와 줄 수 있습니까? 여기에 내 코드 (내 시도 중 하나, 다른 접근법을 시도했지만 아무도 도움이 안됨).
private void setCombo()
{
comboFromOther.DisplayMember = "tbl10_KupaID";
comboFromOther.ValueMember = "tbl10_KupaID";
comboFromOther.DataSource = dsKupotGemel.Tables[0];
}
private void comboToOther_TextChanged(object sender, EventArgs e)
{
comboDetail = changedComboText(2, comboToOther.Text);
textToOther.Text = comboDetail[0];
if (comboDetail[0] == "")
{
}
else
{
comboToOther.SelectedIndex = System.Int32.Parse(comboDetail[1]);
comboToOther.SelectedValue = System.Int32.Parse(comboDetail[2]);
}
}
private string[] changedComboText(int iComboType, string comboString)
{
if (groupCalculate.Visible == true)
{
groupCalculate.Visible = false;
}
string[] kupaDetail = new string[3];
kupaDetail[0] = "";
kupaDetail[1] = "";
kupaDetail[2] = "";
for (int i = 0; i <= dsKupotGemel.Tables[0].Rows.Count - 1; i++)
{
if (comboString == dsKupotGemel.Tables[0].Rows[i][0].ToString())
{
kupaDetail[0] = dsKupotGemel.Tables[0].Rows[i][1].ToString();
kupaDetail[1] = i.ToString();
kupaDetail[2] = comboString;
break;
}
else
{
}
}
return kupaDetail;
}
정확하게 기억한다면, 둘 중 하나만 'SelectedIndex' * 또는 * SelectedValue 중 하나를 설정해야합니다 (하나는 다른 하나를 설정해야합니다). –
Ic. 맞다. SelectedValue를 데이터 소스의 값을 수정하도록 설정하면 comboBox는 선택 변경 이벤트 (예 : SelectedIndexChanged)를 발생시키고 콤보 상자의 값/인덱스는 올바르게됩니다. 관심있는 경우 작업 코드 예제가 있습니다. – Algirdas
제목을 편집했습니다. "[제목에"태그 "가 포함되어 있어야합니까?] (http://meta.stackexchange.com/questions/19190/)"합의가 "아니오, 그렇지 않아야한다"는 것을 참조하십시오. –