微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 如何在datagridview中创建特定的列不可编辑?

使用DataGridView,如何在网格视图本身启用“允许编辑”时使特定列不可编辑?

另外,当DataGridView中的ComboBox中的选定索引发生更改时,如何执行事件?这里,ComboBox是一种列类型.

一个问题是,如何使标题标题与中心对齐?我找不到合适的房产.

解决方法

在这里有几个问题.

(1) How can I make a specific column uneditable in DataGridView?

在要进行不可编辑的特定列上设置ReadOnly标志.

dataGridView.Columns["YourColumnName"].ReadOnly = true;

(2) How can I execute an event when the selected index on a ComboBox in the DataGridView changes?

如果它在你的DataGridView中,它不是一个ComboBox;它是一个DataGridViewComboBoxColumn.根据MSDN

Unlike the ComboBox control,the DataGridViewComboBoxCell does not have Selectedindex and SelectedValue properties. Instead,selecting a value from a drop-down list sets the cell Value property.

这个我不熟悉,因为我自己从未尝试过.您似乎想要订阅EditingControlShowing事件,然后查看something like this是否适合您(稍微调整一下).

(3) How can I make the header title align in the center?

设置HeaderCell.Style.Alignment

dataGridView.Columns["YourColumnName"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐