读书人

怎么双击datagrid中一行,取数据显示在

发布时间: 2012-01-28 22:06:13 作者: rapoo

如何双击datagrid中一行,取数据显示在同一页中的各个text文本框中,最好有例子
如何双击datagrid中一行,取数据显示在同一页中的各个text文本框中,最好有例子

[解决办法]
先问个问题,为什么要双击?如果人在的话加我msn:seamanhy@hotmail.com告诉你
[解决办法]
private void dataGrid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
DataGrid.HitTestInfo hit = this.dataGrid.HitTest(e.X,e.Y) ;

if(hit != null && hit.Type == DataGrid.HitTestType.Cell)
{
if(e.Button==System.Windows.Forms.MouseButtons.Left)
{
if(e.Clicks == 2)
{

DataRowView row = this.m_DataSet.Tables[0].DefaultView[this.dataGrid.CurrentRowIndex] ;
this.txtbox.text=row[ " "].tostring();
this.txtbox.text=row[ " "].tostring();

}

}

}
}
[解决办法]
刚才写错了前面那部分可以不要的!
private void dataGrid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button==System.Windows.Forms.MouseButtons.Left)
{
if(e.Clicks == 2)
{
DataRowView row = this.m_DataSet.Tables[0].DefaultView[this.dataGrid.CurrentRowIndex] ;
this.txtbox.text=row[ " "].tostring();
this.txtbox.text=row[ " "].tostring();
}

}

}
[解决办法]
dataGridView.DataSource 与一 dataBindingSource 绑定:

双击事件 :
DataRow dr =(this.dataBindingSource.Current as DataRowView).Row;

this.textBox1.Text=dr[ "字段名 "].ToString();
...

读书人网 >C#

热点推荐