我有一个问题。这个问题出现在我的脑海里,但我不知道该怎么做。 我有一个2个组合框,每个组合框商店Date
,并且当用户运行该程序和用户在组合框1选择的29/8/2013
一个Date
,自动组合框2从在组合框1中选择的Date
选择30/8/2013
第二天,和/或以前的日期在组合框2将不可用点击或阻塞(因为组合框1为起始日期是选择的29/8/2013
Date
,所以29/8/2013
以前的日期将不会提供给点击或阻塞)使组合框2不能选择与ComboBox相同的值1
我该怎么做呢?
这里是截图:
在上面的截图,i。从组合框1作为开始日期选择日期9/30/2013
。并且ComboBox 2应自动选择9/30/2013
的第二天,因此它假设选择10/01/2013
,并且从9/30/2013
开始的前一个日期将被阻止或无法在组合框2中作为结束日期由用户点击。
我很感谢你的回答。 非常感谢!
下面是代码:
public partial class Trans : Form
{
private List<DateTime> _startDate = new List<DateTime>();
private List<DateTime> _endDate = new List<DateTime>();
public Trans()
{
InitializeComponent();
}
public Trans(Choices _choice)
: this()
{
this._choice = _choice;
}
private void Trans_Load(object sender, EventArgs e)
{
for (int i = 0; i < DateTime.Today.AddYears(1).Subtract(DateTime.Today).TotalDays + 1; i++)
{
_startDate.Add(DateTime.Today.AddDays(i));
}
for (int i = 0; i < DateTime.Today.AddYears(1).Subtract(DateTime.Today).TotalDays + 1; i++)
{
_endDate.Add(DateTime.Today.AddDays(i));
}
StartDateCollection(sender, e);
EndDateCollection(sender, e);
}
private void StartDateCollection(object sender, EventArgs e)
{
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
string query = "SELECT [Dates] FROM [TransRecord]";
conn.Open();
using (OleDbDataAdapter _adapter = new OleDbDataAdapter(query, conn))
{
comboBox1.DataSource = _startDate;
comboBox1.FormatString = "M/dd/yyyy";
comboBox1.FormattingEnabled = true;
}
}
}
private void EndDateCollection(object sender, EventArgs e)
{
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
string query = "SELECT [Dates] FROM [TransRecord]";
conn.Open();
using (OleDbDataAdapter _adapter = new OleDbDataAdapter(query, conn))
{
comboBox2.DataSource = _endDate;
comboBox2.FormatString = "M/dd/yyyy";
comboBox2.FormattingEnabled = true;
}
}
}
}
}
你怎么填充combobox1? – 4dmonster
+1为良好的逻辑问题 –
海,我会在问题中发布代码。对不起,不要提前发布 – Kaoru