组合框在编辑模式下的DataGridView [英] ComboBox in DatagridView in Edit Mode

查看:247
本文介绍了组合框在编辑模式下的DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有与上表负荷需要从数据库的值设置为true(非编辑)只读模式一个DataGridView。当我设置了只读模式为假(编辑模式),我希望有一个特定的列(如系),以可见的组合框,所以我可以从中选择值。而当我进入只读模式,组合框应该会消失,DataGridView中应正常显示。如何实现呢?
我正在使用C#框架4.0的WinForms

I have a DataGridView with read-only mode set to true (non-editable) which takes values from a database on form load. When I set the read-only mode to false (editable mode), I want a particular column (eg. Department) to visible as ComboBox so i can select values from there. And when i enter the Read-Only mode, the ComboBox should disappear and DataGridView should be visible as normal. How to achieve it? I am using C# framework 4.0, Winforms

推荐答案

请参阅在的组合框与只读行为

您也可以改变 的DisplayStyle 根据当 DataGridView的只读属性被改变了。设置的DisplayStyle 来的 DataGridViewComboBoxDisplayStyle.Nothing 将隐藏下拉按钮。

You could also change the DisplayStyle based on when the readonly of the DataGridView property is changed. Setting the DisplayStyle to DataGridViewComboBoxDisplayStyle.Nothing will hide the drop down button.

例如,改变有一个按钮,点击只读属性将是这个样子:

For example, changing the ReadOnly property with a button click would look something like this:

private void mChangeReadOnlyButton_Click(object sender, EventArgs e)
{
   ComboBoxColumn2.DisplayStyle = (dataGridView1.ReadOnly) ?
      DataGridViewComboBoxDisplayStyle.ComboBox :
      DataGridViewComboBoxDisplayStyle.Nothing;
   dataGridView1.ReadOnly = !dataGridView1.ReadOnly;
}



编辑:

Editable:

只读:

这篇关于组合框在编辑模式下的DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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