扩展DataGridView 的功能(四)在用友金蝶等财务软件中,经常需要输入货币类型的数据, 那么这种输入框要如何制作呢?

 借助于强大的 DataGridView 控件, 我们可以轻易的制作出这种效果,见下图.

扩展DataGridView 的功能(四)

 

要扩展 DataGridView 的列类型,我们只需要从 DataGridViewColumn 类中派生出一个新的类,并且为这个列添加对应的单元格模板即可(从 DataGridViewCell 类中派生)。

 

代码其实超级简单, 新增一个 Column 类型

    public class DataGridViewCurrencyColumn : DataGridViewColumn
    {
        
public DataGridViewCurrencyColumn()
            : 
base(new DataGridViewCurrencyCell())
        {
            Resizable 
= DataGridViewTriState.False;
            
//固定宽度
            Width = 120;
        }

        
public override sealed DataGridViewTriState Resizable
        {
            
get { return base.Resizable; }
            
set { base.Resizable = value; }
        }
    }

相关文章:

  • 2021-11-13
  • 2021-06-21
  • 2021-12-08
  • 2021-12-04
  • 2021-11-09
  • 2022-01-30
  • 2021-12-04
  • 2022-03-05
猜你喜欢
  • 2022-12-23
  • 2021-07-05
  • 2021-09-20
  • 2021-09-05
  • 2021-07-09
  • 2021-08-08
相关资源
相似解决方案