DataGridView和Excel [英] DataGridView and Excel
本文介绍了DataGridView和Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,如果你回答我,我将不胜感激。
我写了一个C#程序,我已经将excel文件导出到我的表格'的DataGridView中赢得应用程序,但我有一个问题,我不知道如何在DGV中显示我的数字与千分隔符,而DefaultCellStyle不能解决这个问题。
我该怎么办?
提前感谢
I have a question and I''ll be grateful if you answer me .
I have written a C# program and I''ve exported excel files to my form''s DataGridView in my win app but I have a problem , I don''t know how I can show my numbers with thousand separator in DGV while DefaultCellStyle doesn''t work for solving this problem .
What should I do?
thanks in advance
推荐答案
为CellFormatting添加处理程序
你的网格事件,因此:
Add a handler for theCellFormatting
event of your grid, thus:
myGridView.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.myGridView_CellFormatting);
然后添加获取单元格文本并根据自己的风格调整的处理程序;类似于:
Then add a handler to get the cell''s text and adjust it to your own style; something like:
private void myGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
string strData;
if (e.Value != null)
{
strData = (string)e.Value;
if (myGridView.Columns[e.ColumnIndex].Name == // "< your column name here >")
{
// Adjust the text of the cell to the correct format and paste it back
e.Value = // < adjust the text as required here >
e.FormattingApplied = true;
}
}
}
这篇关于DataGridView和Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文