gpt4 book ai didi

c# - 如何使特定列在datagridview中不可编辑?

转载 作者:太空狗 更新时间:2023-10-29 20:05:35 30 4
gpt4 key购买 nike

使用 DataGridView,当 GridView 本身启用了“允许编辑”时,如何使特定列不可编辑?

此外,当 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;

关于c# - 如何使特定列在datagridview中不可编辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11282729/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com