C#问题
两个combox下拉列表框,一个是年份,一个是月份要求条件如下:
年份选择框:可选年份为当前年份之后5年(包括当前年份),
如果当前年份为2010,月份为10,则年份选择为2010-2014
月份选择 2010年时为10,11,12;其它年份为1-12
C#的啊
急 在线等 拜托……
--------------------编程问答-------------------- 建议转C#版面问问。 --------------------编程问答-------------------- 发错区了吧,楼主。 --------------------编程问答-------------------- 哎、、、、、
浪费啊 --------------------编程问答-------------------- 不浪费,我帮你转区了。
--------------------编程问答-------------------- CSDN社区 - .NET技术 - C#
--------------------编程问答-------------------- 你是想用WinForm做,还是WPF做? --------------------编程问答-------------------- ~~o(>_<)o ~~ 已经改了、、、、 --------------------编程问答-------------------- Winform做 --------------------编程问答--------------------
谢谢 O(∩_∩)O~ --------------------编程问答-------------------- 呵呵,又是一个级联操作的问题。。。。 --------------------编程问答-------------------- 级联问题,然后取月份的时候判断一下当前月份不就行了啊 --------------------编程问答-------------------- 用DateTime获取当前的日期,取出年份,清空年份的Combox,再填充当前年份后的五年;在年份的 选择改变 的事件中,先清空月份的Combox,再判断所选年份是否是当前年份,如果是则用当前月份之后的月填充月份的Combox,否则用1到12填充。 --------------------编程问答--------------------
这个知道 关键是 怎么取的或者说让下拉列表框中:可选年份为当前年份之后5年(包括当前年份),
--------------------编程问答--------------------
--------------------编程问答--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ComboTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
int year = System.DateTime.Now.Year;
for (int i = 0; i < 5; i++)
{
this.comboBox1.Items.Add(year + i);
}
for(int i = 10;i <= 12;i++)
{
this.comboBox2.Items.Add(i);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(this.comboBox1.SelectedItem.ToString().Equals("2010"))
{
this.comboBox2.Items.Clear();
for (int i = 10; i <= 12; i++)
{
this.comboBox2.Items.Add(i);
}
this.comboBox2.Text = "10";
}
else
{
this.comboBox2.Items.Clear();
for (int i = 1; i <= 12; i++)
{
this.comboBox2.Items.Add(i);
}
this.comboBox2.Text = "1";
}
}
}
}
不能用
for (int i = DateTime.Now.Year; i < DateTime.Now.Year+5; i++)
{
comboBox1.Items.Add(i);
}
这个吗? --------------------编程问答-------------------- 额。14楼的说了……
迟一步…… --------------------编程问答--------------------
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
cbYear.Items.Clear();
DateTime dt = DateTime.Today;
int year = dt.Year;
for (int i = 0; i < 5; i++)
{
cbYear.Items.Add(year++);
}
}
private void cbYear_SelectedIndexChanged(object sender, EventArgs e)
{
cbMonth.Items.Clear();
int year = (int)cbYear.SelectedItem;
if (year == DateTime.Today.Year)
{
int month = DateTime.Today.Month;
for (int i = month; i < 13; i++)
{
cbMonth.Items.Add(i);
}
}
else
{
for (int i = 1; i < 13; i++)
{
cbMonth.Items.Add(i);
}
}
}
}
for VS2008 --------------------编程问答--------------------
这个得到的 2010年的 有九月份的哦 改了下就可以了 thanks --------------------编程问答-------------------- using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace csdn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//年的changed事件
private void cbYear_SelectedIndexChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(cbYear.SelectedItem.ToString()))
return;
if (cbYear.SelectedItem.ToString().Equals(DateTime.Now.ToString("yyyy")))
{
cbMonth.Items.Clear();
for (int i = DateTime.Now.Month+1; i < 13; i++)
{
cbMonth.Items.Add(i);
}
}
else
{
cbMonth.Items.Clear();
for (int i = 1; i < 13; i++)
{
cbMonth.Items.Add(i);
}
}
}
//页面加载事件
private void Form1_Load(object sender, EventArgs e)
{
for(int i=0;i<5;i++)
{
this.cbYear.Items.Add(DateTime.Now.AddYears(i).ToString("yyyy"));
}
}
}
}
--------------------编程问答-------------------- 噢耶 多谢各位大侠指点 已经可以了
没想到了 发错了地方 也有这么多豪杰相助 多谢了 、、、、、 --------------------编程问答-------------------- public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
cbYear.Items.Clear();
DateTime dt = DateTime.Today;
int year = dt.Year;
for (int i = 0; i < 5; i++)
{
cbYear.Items.Add(year++);
}
}
private void cbYear_SelectedIndexChanged(object sender, EventArgs e)
{
cbMonth.Items.Clear();
int year = (int)cbYear.SelectedItem;
if (year == DateTime.Today.Year)
{
int month = DateTime.Today.Month;
for (int i = month; i < 13; i++)
{
cbMonth.Items.Add(i);
}
}
else
{
for (int i = 1; i < 13; i++)
{
cbMonth.Items.Add(i);
}
}
}
}
补充:.NET技术 , C#