2013-05-04
展开全部
你的问题说法不清楚……是不是你想问:双击listBox之后弹出的只是选中的文字,我现在要显示ListBox中所有的文字?如果是弹出来看我这个例子: 关键代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsAppTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void listBox1_DoubleClick(object sender, EventArgs e)
{
string s = ""; foreach (var item in listBox1.Items)
{
s += item.ToString()+"\n";
} MessageBox.Show(s);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsAppTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void listBox1_DoubleClick(object sender, EventArgs e)
{
string s = ""; foreach (var item in listBox1.Items)
{
s += item.ToString()+"\n";
} MessageBox.Show(s);
}
}
}
2013-05-04
展开全部
SqlConnection conn = BaseClass.DBConn.CjCon();//创建一个SQL SERVER连接对象。
try
{
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select 姓名年龄等 from xsb where ID=点击获取的学生ID", conn);
DataSet ds = new DataSet();
sda.Fill(ds); this.listView1.Columns.Add("xh", 80, HorizontalAlignment.Center);
this.listView1.Columns.Add("姓名", 60, HorizontalAlignment.Center);//增加列标题
listView1.View = View.Details;
listView1.GridLines = true;//显示网格线。。
string[] str = new string[2];
foreach (DataRow row in ds.Tables[0].Rows)
{
str[0] = row["学号"].ToString();
str[1] = row["xm"].ToString();
ListViewItem item = new ListViewItem(str, 0);
listView1.Items.Add(item);
}
}
catch (Exception er)
{
MessageBox.Show(er.ToString());
conn.Close();
}
item.OnItemDoubleClick += new ItemDoubleClickEvent(item_OnItemDoubleClick);给你的ListBox中每个Item添加双击事件
try
{
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select 姓名年龄等 from xsb where ID=点击获取的学生ID", conn);
DataSet ds = new DataSet();
sda.Fill(ds); this.listView1.Columns.Add("xh", 80, HorizontalAlignment.Center);
this.listView1.Columns.Add("姓名", 60, HorizontalAlignment.Center);//增加列标题
listView1.View = View.Details;
listView1.GridLines = true;//显示网格线。。
string[] str = new string[2];
foreach (DataRow row in ds.Tables[0].Rows)
{
str[0] = row["学号"].ToString();
str[1] = row["xm"].ToString();
ListViewItem item = new ListViewItem(str, 0);
listView1.Items.Add(item);
}
}
catch (Exception er)
{
MessageBox.Show(er.ToString());
conn.Close();
}
item.OnItemDoubleClick += new ItemDoubleClickEvent(item_OnItemDoubleClick);给你的ListBox中每个Item添加双击事件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询