组合框选择多个项目

时间:2012-11-01 13:20:25

标签: c# wpf combobox

有人可以解释这种行为吗?

enter image description here


不仅MouseOver突出显示多个项目(非预期),而且当我Select项目时(鼠标结束)代码转到Selection_Changed事件,该事件改变了右边的图片它(按预期)但在加载图片时,会出现一条错误消息,指出路径中存在无效字符。


BD.Shape xShape = new BD.Shape();
comboBoxShapes.ItemsSource = xShape.GetListOfShapes();

 public List<String> GetListOfShapes()
    {
        List<String> iList = new List<String>();
        try
        {
            GetConnectionString iGet = new GetConnectionString();
            System.Data.OleDb.OleDbConnection iConnect = new System.Data.OleDb.OleDbConnection();
            iConnect.ConnectionString = iGet.ConnectionString();
            iConnect.Open();
            System.Data.OleDb.OleDbCommand iCommand = new System.Data.OleDb.OleDbCommand();
            iCommand.Connection = iConnect;
            iCommand.CommandText = "Select ShapeName from Shapes ";
            System.Data.OleDb.OleDbDataReader iRead = iCommand.ExecuteReader();
            while (iRead.Read())
            {
                Shape iShape = new Shape();
                iShape.ShapeName = iRead["ShapeName"].ToString();
                iList.Add(iShape.ShapeName);
            }

        }
        catch
        {
            MessageBox.Show("Someone better call batman or something `\\(^_^)_/`");
        }
        return iList;
    }

enter image description here


请注意,如果我选择其他任何带有短划线-的内容,则只选择一个项目。没有隐藏/无效的字符......

1 个答案:

答案 0 :(得分:1)

您确定数据中没有换行符吗?

调试该列表中的项目数。

 string same = "same" + Environment.NewLine + "next Line";
 List<string> lstring = new List<string> { "one", "two - a", "two - b", "three", "three", same, same };
 cb1.ItemsSource = lstring;

这具有您描述的选择行为。