winform中dataGridView有一个列是float类型数值问题

yezhendong185 2010-09-03 04:38:52
我现在在datagridview中有一个列是float类型的数值,现在有一些数字比如12.01 15 4.5我要他们统一后面保留俩个数,应该怎么做。就是要显示的结果是12.01 15.00 4.50.
...全文
297 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
yezhendong185 2010-09-06
  • 打赏
  • 举报
回复
谢谢楼上各位,问题解决!!!
glest 2010-09-06
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 yezhendong185 的回复:]

引用 7 楼 dfdfdfjddlfd 的回复:
this.dataGridView1.DefaultCellStyle.Format = "N2";


此方法行不通
[/Quote]

this.column1.DefaultCellStyle.Format = "N2";//column1为需要设置格式的列名
uvvvw 2010-09-06
  • 打赏
  • 举报
回复
学习了
yezhendong185 2010-09-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 dfdfdfjddlfd 的回复:]
this.dataGridView1.DefaultCellStyle.Format = "N2";
[/Quote]

此方法行不通
DevinHu 2010-09-03
  • 打赏
  • 举报
回复
this.dataGridView1.DefaultCellStyle.Format = "N2";
xiaodru88 2010-09-03
  • 打赏
  • 举报
回复
字段里的DisplayFormat设置为0.00就行了
TBCDField(mDataSet.Fields[I]).DisplayFormat= '0.00 ';
new_BCBER 2010-09-03
  • 打赏
  • 举报
回复
其行为中的Format属性设为 N2 即可
dancingbit 2010-09-03
  • 打赏
  • 举报
回复
怎么个没有办法设置?

MSDN中都有现在的例子的:

// Configures the appearance and behavior of a DataGridView control.
private void InitializeDataGridView()
{
// Initialize basic DataGridView properties.
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.BackgroundColor = Color.LightGray;
dataGridView1.BorderStyle = BorderStyle.Fixed3D;

// Set property values appropriate for read-only display and
// limited interactivity.
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.AllowUserToOrderColumns = true;
dataGridView1.ReadOnly = true;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.MultiSelect = false;
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
dataGridView1.AllowUserToResizeColumns = false;
dataGridView1.ColumnHeadersHeightSizeMode =
DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
dataGridView1.AllowUserToResizeRows = false;
dataGridView1.RowHeadersWidthSizeMode =
DataGridViewRowHeadersWidthSizeMode.DisableResizing;

// Set the selection background color for all the cells.
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.White;
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black;

// Set RowHeadersDefaultCellStyle.SelectionBackColor so that its default
// value won't override DataGridView.DefaultCellStyle.SelectionBackColor.
dataGridView1.RowHeadersDefaultCellStyle.SelectionBackColor = Color.Empty;

// Set the background color for all rows and for alternating rows.
// The value for alternating rows overrides the value for all rows.
dataGridView1.RowsDefaultCellStyle.BackColor = Color.LightGray;
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.DarkGray;

// Set the row and column header styles.
dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Black;
dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.Black;

// Set the Format property on the "Last Prepared" column to cause
// the DateTime to be formatted as "Month, Year".
dataGridView1.Columns["Last Prepared"].DefaultCellStyle.Format = "y";

// Specify a larger font for the "Ratings" column.
using (Font font = new Font(
dataGridView1.DefaultCellStyle.Font.FontFamily, 25, FontStyle.Bold))
{
dataGridView1.Columns["Rating"].DefaultCellStyle.Font = font;
}

// Attach a handler to the CellFormatting event.
dataGridView1.CellFormatting += new
DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);
}



yezhendong185 2010-09-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dancingbit 的回复:]
DefaultCellStyle属性
[/Quote]
这个属性怎么设置?麻烦告诉下好吗!我看了下好像没办法设置!
dancingbit 2010-09-03
  • 打赏
  • 举报
回复
DefaultCellStyle属性
yezhendong185 2010-09-03
  • 打赏
  • 举报
回复
我如果转换成string就可以实现,但是string类型的排序正方是直接绝对值进行排序的有问题所有必须是数字类型的排序才不会出现string类型的排序错误。
培训课件内容: 第一部分 .NET框架(0.5天) 第二部分 Winform编程(2天) 第三部分 Ado.NET(2天) 第四部分 WPF技术(1.5天) 第五部分 WCF开发技术(1.5天) 第六部分-项目实战(1.5天) 详细内容: 第一部分 .NET框架(0.5天) 1. 了解.NET之前诞生前的世界 2. Microsoft .NET 框架结构 3. Microsoft .NET 框架结构 4. .NET Framework 概述 5. .Net Framework 2.0/ 3.0/3.5 6. 公共语言运行库 7. 公共语言运行库的优点 8. NET Framework 类库概述 9. NET Framework 类库结构 10. NET Framework 类库功能 11. 公共语言运行时 CLR 12. CLR 和 MSIL(Microsoft 间语言) 13. 应用程序执行过程 14. 了解MSIL 15. MSIL+元数据 16. 多语言支持和语言互操作的基础 -CLS 和 CTS公共语言规范 17. 应用程序域 18. 程序集的一些基本概念 19. C# 语言的优点 20. 认识我们的开发利器visual studio 2008 Team 第二部分 WindowsForm(2天) (1) C#基本编程知识什么是关键字 (2) C#的合法语句 (3) 变量的声明变量声明格式 (4) 变量类型数值类型:int;float等 (5) 快速了解快速了解对话框控件应用 (6) 快速了解第三方控件的应用 (7) 委托和事件 (8) 定义委托 (9) 实例化委托 (10) 调用委托 (11) 异步委托 (12) 异步委托的定义 (13) 异步委托的四种调用方法 (14) 什么是事件 (15) 定义事件 (16) 订阅事件 (17) 触发事件 (18) 引发事件 (19) 深入了解事件Event (20) 观察者模式 (21) Obseve模式结构 (22) Observer 示例程序演示 (23) Observer 与事件 (24) 自定义控件和用户控件C#控件 (25) 事件驱动开发使用 (26) GDI+图形编程 第三部分 Ado.NET(2天) (1) ADO.NET结构 (2) ADO.NET工作原理 (3) 数据提供者(Data Provider) (4) Data Provider 优点 (5) 数据集(DataSet) (6) DataSet结构 (7) DataSet优点 (8) ADO.NET 对象模型 (9) 数据库相关控件的使用DataGridView控件 (10) DataGridView-显示数据基本方法 (11) DataGridView使用动态编程显示数据 (12) DataGridView保存修改后的数据关键知识 (13) 事务处理 (14) Sql 基本语法练习 (15) 什么是存储过程 (16) SQL注入攻击介绍 (17) 遭受SQL注入式攻击的基本原理 (18) 使用参数化查询提高数据安全 (19) 数据安全总结 (20) IDE环境整合使用EXPRESS 数据库开发应用 第四部分 WPF开发技术(1.5天) (1) 什么是WPF (2) WPF应用程序 (3) 建立第一WPF应用程序项目 (4) WPF的重要技术XAML (5) XAML语法 (6) 学习Expression Blend 专业的WPF设计工具 (7) 使用EB WPF客户端实战 (8) 刨析XAML (9) XAML语法 (10) 认识WPF的主要控件 (11) 动画什么 (12) 动画的3个重要概念 (13) 使用时间线和故事板 (14) 动画使用触发器 (15) 数据绑定Binding (16) 动画开发实战 第五部分 WCF开发技术(1.5天) (1) 从SOA说起S-Server (2) 什么是WCF Windows Communication Foundation (3) WCF-各种分布式技术统一江湖 (4) 实例了解什么是WCF (5) WCF通信模型 (6) 协定,契约,合同 (7) Contract分类协定分类 (8) 4个最主要组件WCF (9) Demo-天气预报服务功能设计 (10) WCF的基本概念-Endpoint 终节点 (11) WCF的基本概念-ABC (12) WCF的基本概念-Endpoint与ABC包含关系 (13) 特殊的Endpoint-Mex节点回忆SOA的特点 (14) Binding绑定的作用 (15) Binding绑定协议的选择 (16) Address地址的作用 (17) 认识主要的协议 (18) WCF通信模型 (19) 托管与宿主托管 (20) 消息模式 (21) 消息模式-单向模式 (22) 请求/答复请求/答复模式 (23) 双工模式 (24) WCF Behavior是什么 (25) 主要的服务行为实例管理 (26) WCF 安全控制 第六部分 WPF+WCF项目实战(1.5天) (1) 项目开发-聊天室基于WPF+WCF的聊天室 (2) 需求分析和功能设计 (3) 聊天室系统详细设计 (4) 聊天室契约设计 (5) 聊天室实现: 宿主服务器 (6) 聊天室实现客户端 (7) WPF实现客户端开发

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧