using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace testmenu
{
public class yearP
{
public string tyear { get; set; }
public int pyear { get; set; }
}
}
2.สร้าง procedure ใน Form
void AddValue()
{
comboBox1.Items.Clear();
int year = DateTime.Now.Year;
string a = year.ToString();
//comboBox1.Items.Add(a);
List<yearP> list = new List<yearP>();
for (int i = 1; i <= 10; i++)
{
int my = year + i;
string tmy = (my + 543).ToString();
list.Add(new yearP() { tyear = tmy, pyear = my });
}
for (int i = 0; i <= 10; i++)
{
int my = year - i;
string tmy = (my + 543).ToString();
list.Add(new yearP() { tyear = tmy, pyear = my });
}
comboBox1.DataSource = list;
comboBox1.ValueMember = "pyear";
comboBox1.DisplayMember = "tyear";
}
3.เรียกใช้
private void FormMain_Load(object sender, EventArgs e)
{
AddValue();
comboBox1.SelectedIndex = 10;
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น