关于ComboBox的时间控件问题

FEIHUKT 2009-06-09 05:06:48
三个combobox控件
第一个先择年
第二个选择月
第三个选择日
引用别人的
"
combobox1.Items.Add("2009");
combobox1.Items.Add("2008");
combobox1.Items.Add("2007");
combobox1.Items.Add("2006");
combobox1.Items.Add("2005");
combobox1.Items.Add("2004");
combobox1.Items.Add("2003");

也可以写个循环 "
问题:
1.用for循环来怎么写?
2.代码写在哪里。写在combobox的change事件里吗?
3.要三个combobox关联.怎么写?
4.要考虑润年润月的情况
4.写出来的时候。我要在datagridview里显示自己所选择的日期怎么写?

...全文
34 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qqqwwwwww 2009-07-25
  • 打赏
  • 举报
回复

//判断闰年
private bool checkleap(int year)
{
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
return true;
else return false;
}
//绑定每月的天数
private void binddays(int year, int month)
{
int i;
ArrayList alday = new ArrayList();

switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
for (i = 1; i <= 31; i++)
alday.Add(i);
break;
case 2:
if (checkleap(year))
{
for (i = 1; i <= 29; i++)
alday.Add(i);
}
else
{
for (i = 1; i <= 28; i++)
alday.Add(i);
}
break;
case 4:
case 6:
case 9:
case 11:
for (i = 1; i <= 30; i++)
alday.Add(i);
break;
}
this.comboBox3.DataSource = alday;

}
private void Form1_Load(object sender, EventArgs e)
{


//绑定年
ArrayList alyear = new ArrayList();
int i;
for (i = 1900; i <= 2099; i++)
alyear.Add(i);
this.comboBox1.DataSource = alyear;



//绑定月
ArrayList almonth = new ArrayList();
for (i = 1; i <= 12; i++)
almonth.Add(i);
this.comboBox2.DataSource = almonth;

int year, month;
year = Int32.Parse(this.comboBox1.SelectedValue.ToString());
month = Int32.Parse(this.comboBox2.SelectedValue.ToString());
binddays(year, month);//绑定天

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int year, month;
year = Int32.Parse(this.comboBox1.SelectedValue.ToString());
month = 1;
binddays(year, month);

}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
int year, month;
year = Int32.Parse(this.comboBox1.SelectedValue.ToString());
month = Int32.Parse(this.comboBox2.SelectedValue.ToString());
binddays(year, month);

}


已调试过
FEIHUKT 2009-06-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 happyflystone 的回复:]
c?
[/Quote]
能不能帮个忙啊。楼上的.
-狙击手- 2009-06-09
  • 打赏
  • 举报
回复
c?

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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