求助!!!查错comboBox取值问题
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//System.DateTime currentTime = new System.DateTime();
private bool Check(int year)
{
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
return true;
else
return false;
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 2000; i <= 2099; i++)
{
comboBox1.Items.Add(i.ToString());
}
for (int i = 1; i <= 12; i++)
{
comboBox2.Items.Add(i.ToString());
}
for (int i = 1; i <= 31; i++)
{
comboBox3.Items.Add(i.ToString());
}
}
private int MonthToDay(int month)
{
int j = int.Parse(textBox1.Text.ToString());
int h = System.Convert.ToInt32(comboBox3.SelectedValue) + j;
int year = System.Convert.ToInt32(comboBox1.SelectedValue);
//MessageBox.Show( year.ToString());
month = System.Convert.ToInt32(comboBox2.SelectedValue);
int day = System.Convert.ToInt32(comboBox3.SelectedValue);
MessageBox.Show(day.ToString());
int y = 0;
if (Convert.ToInt32(comboBox2.SelectedValue) == 2)
{
if (Check(year))
{
y = 29;
}
else
{
y = 28;
}
return y;
}
if ((Convert.ToInt32(comboBox2.SelectedValue) == 1) || (Convert.ToInt32(comboBox2.SelectedValue) == 3) || (Convert.ToInt32(comboBox2.SelectedValue) == 5) || (Convert.ToInt32(comboBox2.SelectedValue) == 7) || (Convert.ToInt32(comboBox2.SelectedValue) == 8) || (Convert.ToInt32(comboBox2.SelectedValue) == 10))
{
y = 31;
}
else
{
if (Convert.ToInt32(comboBox2.SelectedValue) == 12)
{
y = 31;
if (h > 31)
{
year = year + 1;
month = month + 1;
}
else
{
y = 31;
}
return y;
}
else
{
y = 30;
}
return y;
}
return y;
}
private void btnOK_Click(object sender, EventArgs e)
{
//int y;
int j = int.Parse(textBox1.Text.ToString());
int h = System.Convert.ToInt32(comboBox3.SelectedValue) + j;
int year = System.Convert.ToInt32(comboBox1.SelectedValue);
int month = System.Convert.ToInt32(comboBox2.SelectedValue);
int day = System.Convert.ToInt32(comboBox3.SelectedValue);
int z = MonthToDay(System.Convert.ToInt32(comboBox2.SelectedValue));
int sum = 0;
sum = sum+day + z;
//MessageBox(sum= "+sum+ ");
//
if (sum % j > MonthToDay(month))
{
month = month + 1;
day = sum % j;
}
else
{
day = sum % j;
}
MessageBox.Show( "3 ",year.ToString());
MessageBox.Show( "4 ", month.ToString());
textBox2.Text = "下次时间大约是 " + year.ToString() + "年 " + month.ToString() + "月 " + day.ToString() + "日 ";
}
}
}
[解决办法]
楼主还是先描述描述问题吧,只贴代码,谁也不知道是什么,也不愿意看那么多代码
[解决办法]
使用Text属性取值就可以了。
[解决办法]
LS說的對
[解决办法]
SelectedValue属性只适用于绑定的方式,如果是非绑定,应该使用SelectedItem,或直接取其Text属性,或通过Items[combobox.SelectedIndex]来取值。
[解决办法]
最好进行调试一下啊,要是有错应该可以显示出来的啊