我有个问题。这个问题出现在我的脑海中,但我不知道该怎么做。我有一个 2 ComboBoxes,每个 ComboBox 存储 a Date
,当用户运行程序并用户在 ComboBox 1 中选择 aDate
时,ComboBox 2 自动从29/8/2013
ComboBox 1 中选择的第二天选择,和/或 ComboBox 2 中的上一个日期不会可点击或屏蔽(因为 ComboBox 1 作为开始日期选择的是,所以之前的日期将不可点击或屏蔽)30/8/2013
Date
Date
29/8/2013
29/8/2013
我怎么做?
这是屏幕截图:
在上面的屏幕截图中,我9/30/2013
从 ComboBox 1 中选择日期作为开始日期。并且 ComboBox 2 应该自动选择 的下一天9/30/2013
,因此它假设选择10/01/2013
并且上一个日期9/30/2013
将被阻止或无法被用户在 ComboBox 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;
}
}
}
}
}