标签:rgs tostring http edit ring view 控件 游记 红楼梦
实现效果:
知识运用:
ListBox控件的SelectedItem属性 //获取或设置ListBox控件中当前选定的数据项
public Object SelectedItem{ get;set; }
实现代码:
private DataTable dt; private DataColumn dc; private DataColumn dc1; private void Form1_Load(object sender, EventArgs e) { dt = new DataTable(); dc = new DataColumn("book"); dc1 = new DataColumn("author"); dt.Columns.Add(dc); dt.Columns.Add(dc1); dt.Rows.Add("西游记", "吴承恩"); dt.Rows.Add("水浒传", "施耐庵"); dt.Rows.Add("红楼梦", "曹雪芹"); dt.Rows.Add("三国演义", "罗贯中"); listBox1.DataSource=dt; listBox1.DisplayMember="book"; listBox1.ValueMember = "author"; } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (listBox1.SelectedItem.ToString() != null) { textBox1.Text = ((DataRowView)listBox1.SelectedItem).Row[dc].ToString(); textBox2.Text = ((DataRowView)listBox1.SelectedItem).Row[dc1].ToString(); } }
标签:rgs tostring http edit ring view 控件 游记 红楼梦
原文地址:https://www.cnblogs.com/feiyucha/p/10161084.html