我想在c#中打印网格视图的列标题的所有日期。 [英] I want to print all the dates with column header for the grid view in c#.
本文介绍了我想在c#中打印网格视图的列标题的所有日期。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮我在网格视图中添加日期列名。
我知道我必须把我的代码放在循环中才能生成这个。
请告诉我如何循环添加网格视图列。
我收到错误,如同列名已经存在。
我尝试过:
//天是月初(2018/05/01)
$ b (b = i; i< days,i ++)
+ d.shortdatestring())
dt.column.add(dt);
d = d.adddays(1);
}
Please help me to add dates column name in a grid view.
I know i have to put my code in loop to generate this.
kindly tell me how to loop addition of Grid view columns.
I am getting error like same column name is already exist.
What I have tried:
//days is start of month(2018/05/01)
for(i=1;i<days,i++)
{
datacolumn dt= new datacolumn(d.dateofweek()+d.shortdatestring())
dt.column.add(dt);
d=d.adddays(1);
}
推荐答案
请尝试以下代码解决您的问题。
这会将日期列添加到datagridview。
Try below code for your problem.
This will add date columns to datagridview.
//Get current date
DateTime dt = DateTime.Now;
//Get first date
var startDate = new DateTime(dt.Year, dt.Month, 1);
//Get tota no of days
int days = DateTime.DaysInMonth(dt.Year, dt.Month);
//Loop on days
for (int i = 0; i < days; i++)
{
dataGridView1.Columns.Add("clm_" + startDate.ToShortDateString(), startDate.ToString("yyyy/MM/dd"));
startDate= startDate.AddDays(1);
}
解决了
Sir ..我现在正确地得到了语法...非常感谢帮助我..
Solved
Sir.. I got the syntax now properly... Thanks a lot for helping me..
我找到答案..谢谢先生
I found answer.. thank you sir
这篇关于我想在c#中打印网格视图的列标题的所有日期。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文