首页 > 其他 > 详细

comboBox 下拉宽度自适应

时间:2018-11-14 10:16:44      阅读:202      评论:0      收藏:0      [点我收藏+]

///适用combobox绑定datatable

private void comboBox_DataSourceChanged(object sender, EventArgs e)
{
ComboBox cbb = sender as ComboBox;
string s = "";
foreach (DataRow row in (cbb.DataSource as DataTable).Rows)
{
string str = row[cbb.DisplayMember].ToString();
if (s.Length < str.Length)
{
s = str;
}
}
cbb.DropDownWidth = (int)cbb.CreateGraphics().MeasureString(s, cbb.Font).Width
+ (cbb.Items.Count > cbb.MaxDropDownItems ? SystemInformation.VerticalScrollBarWidth : 0);
}

comboBox 下拉宽度自适应

原文:https://www.cnblogs.com/masiteyi/p/9955980.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!