设置winform DataGridView的显示格式 [英] Set Display format for winform DataGridView

查看:60
本文介绍了设置winform DataGridView的显示格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WinForms开发的新手,目前正在维护以.Net 2.0开发的应用程序

I am new to WinForms development, currently I am maintaining an application developed in .Net 2.0

在应用程序中,我有一个名为长度"的网格,该网格以单位显示值.我已经使用 CellFormatting 事件设置单元格值的格式,否则它只是数字.

In the application, I have grid with column called Length which displays the value with unit. I have used CellFormatting event to format the cell value, otherwise it is just number.

但是当用户开始编辑时,我不想显示单位,应该只允许用户输入数字.

But when user start editing I wouldn't want unit to be displayed, user should be allowed enter only numbers.

有没有直接的方法可以做到这一点?要在网格上设置事件还是属性?

Is there any straight forward way to do it? Events or Properties to be set on the grid?

推荐答案

您可以使用CellStyle Builder设置格式字符串,并将自定义"格式设置为#mm

You can Set you Format String using CellStyle Builder an set the Custom format to # mm

操作方法:

  1. 右键单击网格",然后单击属性"
  2. 在属性窗口中,单击将弹出编辑列"对话框的按钮
  3. 选择要格式化的单元格
  4. 在编辑列"对话框的右侧,选择DefaultCellStyle属性
  5. 单击DefaultCellStyle属性,然后将打开CellStyleBuilder对话框
  6. 这里具有format属性,这将为您提供格式字符串"对话框
  7. 将自定义"属性设置为#mm,您将在底部看到预览
  8. 单击确定...",直到回到网格...

这篇关于设置winform DataGridView的显示格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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