1.跨窗体传值:
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(textBox1.Text);
f2.Show();
}
public Form2(string s)
{
InitializeComponent();
label1.Text = s;
}
2.listview属性
FullRowSelect:鼠标选中
checkbox:选项框
gridlines:表格
3.绑定数据:
private string _NationCode;
public string NationCode
{
get { return _NationCode; }
set { _NationCode = value; }
}
private string _NationName;
public string NationName
{
get { return _NationName; }
set { _NationName = value; }
} //给一个nationcode给一个nationname
查询nation表方法:
public List<Nation> SelectAll()
{
List<Nation> nlist = new List<Nation>();
cmd.CommandText = "select *from Nation";
//调用方法
public Form1()
{
InitializeComponent();
List<Nation> nlist = new NationData().SelectAll();
comboBox1.DataSource = nlist;
comboBox1.DisplayMember = "NationName";
comboBox1.ValueMember = "NationCode";
comboBox1.SelectedValue = "N002";
List<Nation> nlist2 = new NationData().SelectAll();
listBox1.DataSource = nlist2;
listBox1.DisplayMember = "NationName";
listBox1.ValueMember = "NationCode";
}
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Nation n = new Nation();
n.NationCode = dr[0].ToString();
n.NationName = dr[1].ToString();
nlist.Add(n);
}
conn.Close();
return nlist;
}