• combobox重绘时为什么选项是System.Data.DataRowView?
  • 2016/10/5 9:14:56  浏览次数:2344
  • combobox的DrawMode为OwnerDrawVariable,重写DrawItem时,是这样写的:

    private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
    {
         e.DrawBackground();
         e.DrawFocusRectangle();
         e.Graphics.DrawString(scomboBox1.Items[e.Index].ToString(),e.Font, new Pen(e.ForeColor).Brush, e.Bounds);
    }

    但执行后下拉列表框的选项不是想要的内容,而是System.Data.DataRowView。

    这是因为数据绑定时用了DataTable,将scomboBox1.Items[e.Index].ToString()修改成((DataRowView)comboBox1.Items[e.Index])["字段名"].ToString()即可。


合作伙伴:车三百中国联通 太平洋电脑网