加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 04:27:07 所属栏目:百科 来源:网络整理
导读:使用DataGridView,如何在网格视图本身启用“允许编辑”时使特定列不可编辑? 另外,当DataGridView中的ComboBox中的选定索引发生更改时,如何执行事件?这里,ComboBox是一种列类型. 另一个问题是,如何使标题标题与中心对齐?我找不到合适的房产. 解决方法 你在
使用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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读