如何使一个特定的列不可编辑在datagridview的? [英] How to make a specific Column Uneditable In datagridview?

查看:145
本文介绍了如何使一个特定的列不可编辑在datagridview的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用一个DataGridView,我怎样才能使一个特定的列不可编辑,而网格视图本身有允许编辑已启用?



另外,我怎么能执行一个事件当在DataGridView组合框选定的指标发生了变化?在这里,组合框是一个列的类型。



另一个问题是,我怎样才能使居中对齐标题标题?我找不到相应的属性。


解决方案

您已经有了一个几个问题在这里。




(1)如何让特定的列在DataGridView中不可编辑的?




设置 只读 你想使不可编辑的特定列标志。

  dataGridView.Columns [ YourColumnName] =只读真实。 




(2)我怎么能执行一个事件的时候所选择的指数?在DataGridView变化的组合框




如果它在你的DataGridView,它不是一个组合框;这是一个DataGridViewComboBoxColumn。据 MSDN




不像ComboBox控件,该的DataGridViewComboBoxCell不具备的SelectedIndex和SelectedValue的属性。相反,选择从下拉列表中的值设置单元格Value属性。




这一个我不太熟悉,因为我从来没有尝试过自己。看来要订阅 EditingControlShowing 事件,然后看看的这样的事情对你的作品(稍加调整)。




(3)我怎样才能使中央的头标题对齐




设置的 HeaderCell.Style.Alignment

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


Using a DataGridView, how can I make a specific column uneditable while the grid view itself has "Allow editing" enabled?

Also, how can I execute an event when the selected index in a ComboBox in the DataGridView has changed? Here, ComboBox is a column type.

Another question is, how can I make the header title aligned to the center? I can't find the appropriate property.

解决方案

You've got a few questions here.

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

Set the ReadOnly flag on the particular column you want to make uneditable.

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

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

If it's in your DataGridView, it's not a ComboBox; it's a DataGridViewComboBoxColumn. According to 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.

This one I'm not familiar with, as I've never tried it myself. It appears you want to subscribe to the EditingControlShowing event and then see if something like this works for you (with a little tweaking).

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

Set the HeaderCell.Style.Alignment

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

这篇关于如何使一个特定的列不可编辑在datagridview的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆