即鼠标所点击的行
谢谢
我用了一个很笨的办法
public partial class Form1 : Form
{
//构建桥接器
SqlDataAdapter sda = new SqlDataAdapter();
//连接对象
SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=sa;database=stu_manager");
//构建一个本地数据集中的虚拟表
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 窗体加载时填充datagridview
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
sda.SelectCommand = new SqlCommand("select * from class", con);
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
/// <summary>
/// datagridview的单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
//获得一个与被选中行一样架构的新行
DataRow dr = dt.Rows[e.RowIndex];
//我偷懒了,弹出行中每个单元格的值,效果出来了
int j=dt.Columns.Count;
for (int i = 0; i < j;i++ )
{
MessageBox.Show(dr[i].ToString());
}
}
}
}
[此贴子已经被作者于2006-5-23 0:13:38编辑过]