[英]SelectedIndexChanged event is not firing when OwnerDrawFixed mode selected for Combobox in Winform
我有组合框并将DrawMode更改为OwnerDrawFixed并处理了DrawItem事件,但是现在当我尝试将selectedIndex更改为-1时,因为数据库中没有此值。 因此SelectedIndexChanged无法正常工作。
我已经将DropDownStyle
设置为DropDownList
DrawMode
设置为OwnerDrawFixed
抽奖方式:
private void cmbDetTechnician_DrawItem(object sender, DrawItemEventArgs e)
{
try
{
int index = e.Index >= 0 ? e.Index : 0;
var brush = Brushes.Black;
e.DrawBackground();
e.Graphics.DrawString(lstTechnician[index].DisplayName.ToString(), e.Font, brush, e.Bounds, StringFormat.GenericDefault);
e.DrawFocusRectangle();
}
catch
{
}
}
现在我没有雇员ID的值,则应将组合框设置为SelectedIndex
为-1,但它不起作用:
if(_EmployeeID == -1){cmbDetTechnician.SelectedIndex = -1; } else { cmbDetTechnician.SelectedValue = _EmployeeID; }
我也曾尝试处理此组合框的SelectedIndexChanged。 但以上声明后未引发事件。
private void cmbDetTechnician_SelectedIndexChanged(object sender, EventArgs e)
{
CustomMessageBox.Show("HI");
}
请让我知道我做错了什么或任何更好的建议。
问题似乎出在图纸上,而不是SelectedIndex...。
if(e.Index >= 0)
{
int index = e.Index;
var brush = Brushes.Black;
e.DrawBackground();
e.Graphics.DrawString(lstTechnician[index].DisplayName.ToString(), e.Font, brush, e.Bounds, StringFormat.GenericDefault);
e.DrawFocusRectangle();
}
else
{
e.DrawBackground();
e.DrawFocusRectangle();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.