双击DataGrid后。。。。。。。。。 如何双击DataGrid的某行就能得到当前行的数据,private void dataGrid1_Click和DoubleClick事件下写在哪里工作时间不长,还在摸索中,好心的给个完整的代码,CSDN上的列子也看了,就是不知道上面那两个写在哪????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不好意思,补充下,是WINDOWS程序 在属性里找到DoubleClick事件,双击写呀。 string temp = "";dsSongs.Tables["Songs"].Rows[dgSongs.CurrentCell.RowNumber]["name"].ToString().Trim();MessageBox.Show(temp); TO whglq(明天) 在属性里找到DoubleClick事件???我THIS可以点出来,但是双击写??to bing1728(天空无鸟) 你的代码我刚刚从其他的网站上看过,不懂 我双击DataGrid是这个事件 private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne) DataGrid的某行就弹出个新窗体,新窗体用文本框显示此行的详细数据....来个人好么?这个问题有人问了一百遍了,我看的不怎么明白啊, 例如,你的DataGrid 叫dg ,你可以用,dg.CurrentCell.RowNumber获得你双击的行的行号,用dg[行号,列号] 可以获是数据. 这个我知道.就是我想双击DataGrid后弹出另外一个窗体来显示啊DoubleClick()??有用么? 把这里的代码事件修改成双击,//在另一个窗口中修改当前选定的DataGrid的行using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;//主窗体代码namespace Zhzuo{ public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.DataGrid dataGrid1; private DataSet ds; private System.Windows.Forms.Button button1; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { InitializeComponent(); ds = new DataSet("MyDataSet"); InitData(ds); this.dataGrid1.DataSource = this.ds; this.dataGrid1.DataMember = this.ds.Tables[0].TableName; } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.dataGrid1 = new System.Windows.Forms.DataGrid(); this.button1 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.SuspendLayout(); // // dataGrid1 // this.dataGrid1.DataMember = ""; this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid1.Location = new System.Drawing.Point(16, 20); this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.Size = new System.Drawing.Size(340, 160); this.dataGrid1.TabIndex = 0; this.dataGrid1.DoubleClick += new System.EventHandler(this.dataGrid1_DoubleClick); // // button1 // this.button1.Location = new System.Drawing.Point(264, 196); this.button1.Name = "button1"; this.button1.TabIndex = 1; this.button1.Text = "修改"; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(372, 229); this.Controls.Add(this.button1); this.Controls.Add(this.dataGrid1); this.Name = "Form1"; this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); this.ResumeLayout(false); } #endregion private void InitData(DataSet ds) { DataTable dt = new DataTable("TabeHost"); DataColumn dc = new DataColumn("IpAddress",typeof(string)); dt.Columns.Add(dc); dc = new DataColumn("UserName",typeof(string)); dt.Columns.Add(dc); dc = new DataColumn("Password",typeof(string)); dt.Columns.Add(dc); ds.Tables.Add(dt); DataRow dr = dt.NewRow(); dr["IpAddress"] = "192.192.132.229"; dr["UserName"] = "zhzuo"; dr["Password"] = "zhengzuo"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["IpAddress"] = "192.192.132.230"; dr["UserName"] = "11"; dr["Password"] = "12"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["IpAddress"] = "192.192.132.231"; dr["UserName"] = "123"; dr["Password"] = "12"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["IpAddress"] = "192.192.132.232"; dr["UserName"] = "22"; dr["Password"] = "788"; dt.Rows.Add(dr); } private void button1_Click(object sender, System.EventArgs e) { DataRowView drv = (DataRowView)this.BindingContext[this.ds,this.ds.Tables[0].TableName].Current; Form2 form2 = new Form2(drv); form2.ShowDialog(); } private void dataGrid1_DoubleClick(object sender, System.EventArgs e) { button1_Click(button1,EventArgs.Empty); } }}//子窗体代码=======================using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace Zhzuo{ /// <summary> /// Form2 的摘要说明。 /// </summary> public class Form2 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private DataRowView drv; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form2(DataRowView dr) { InitializeComponent(); this.drv = dr; this.textBox1.Text = (string)drv["IpAddress"]; this.textBox2.Text = (string)drv["UserName"]; this.textBox3.Text = (string)drv["Password"]; } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox3 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(28, 16); this.textBox1.Name = "textBox1"; this.textBox1.TabIndex = 3; this.textBox1.Text = "textBox1"; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(28, 56); this.textBox2.Name = "textBox2"; this.textBox2.TabIndex = 4; this.textBox2.Text = "textBox2"; // // textBox3 // this.textBox3.Location = new System.Drawing.Point(28, 92); this.textBox3.Name = "textBox3"; this.textBox3.TabIndex = 5; this.textBox3.Text = "textBox3"; // // button1 // this.button1.Location = new System.Drawing.Point(152, 152); this.button1.Name = "button1"; this.button1.TabIndex = 6; this.button1.Text = "保存"; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(236, 152); this.button2.Name = "button2"; this.button2.TabIndex = 7; this.button2.Text = "退出"; this.button2.Click += new System.EventHandler(this.button2_Click); // // Form2 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(324, 201); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Controls.Add(this.textBox3); this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Name = "Form2"; this.Text = "Form2"; this.ResumeLayout(false); } #endregion private void button1_Click(object sender, System.EventArgs e) { drv["IpAddress"] = this.textBox1.Text; drv["UserName"] = this.textBox2.Text; drv["Password"] = this.textBox3.Text; } private void button2_Click(object sender, System.EventArgs e) { this.Close(); } }} 其他操作可以看,http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx 新手求助一个简单的问题啊,关于image 和bitmapimage的 文本框掩码 运行项目出错,麻烦有经验的看看 把datagirdview查询到的数据插入到数据库中 比较特殊的添加xml节点怎么处理呢? 学了一年多C#,但是感觉好迷茫. 【求助】====C#中Dll引用的问题! ==== Access中,数据类型为"自动编号",新值为"随机"的时候,产生的值会出现复重吗? 请问那个表格控件能提供组合框单元格? VMware Fusion虚拟机里的C#程序如何获取宿主的硬件信息? Datagrid中怎样用颜色区分行。。。。。。。。。。。。。。 下面的语句要怎么修改才是正确的,总提示错误.
dsSongs.Tables["Songs"].Rows[dgSongs.CurrentCell.RowNumber]["name"].ToString().Trim();
MessageBox.Show(temp);
这个问题有人问了一百遍了,我看的不怎么明白啊,
用dg[行号,列号] 可以获是数据.
DoubleClick()??有用么?
//在另一个窗口中修改当前选定的DataGrid的行using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
//主窗体代码
namespace Zhzuo
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private DataSet ds;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
ds = new DataSet("MyDataSet");
InitData(ds);
this.dataGrid1.DataSource = this.ds;
this.dataGrid1.DataMember = this.ds.Tables[0].TableName;
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(16, 20);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(340, 160);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.DoubleClick += new System.EventHandler(this.dataGrid1_DoubleClick);
//
// button1
//
this.button1.Location = new System.Drawing.Point(264, 196);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "修改";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(372, 229);
this.Controls.Add(this.button1);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false); }
#endregion private void InitData(DataSet ds)
{
DataTable dt = new DataTable("TabeHost");
DataColumn dc = new DataColumn("IpAddress",typeof(string));
dt.Columns.Add(dc);
dc = new DataColumn("UserName",typeof(string));
dt.Columns.Add(dc);
dc = new DataColumn("Password",typeof(string));
dt.Columns.Add(dc);
ds.Tables.Add(dt);
DataRow dr = dt.NewRow();
dr["IpAddress"] = "192.192.132.229";
dr["UserName"] = "zhzuo";
dr["Password"] = "zhengzuo";
dt.Rows.Add(dr); dr = dt.NewRow();
dr["IpAddress"] = "192.192.132.230";
dr["UserName"] = "11";
dr["Password"] = "12";
dt.Rows.Add(dr); dr = dt.NewRow();
dr["IpAddress"] = "192.192.132.231";
dr["UserName"] = "123";
dr["Password"] = "12";
dt.Rows.Add(dr); dr = dt.NewRow();
dr["IpAddress"] = "192.192.132.232";
dr["UserName"] = "22";
dr["Password"] = "788";
dt.Rows.Add(dr);
} private void button1_Click(object sender, System.EventArgs e)
{
DataRowView drv = (DataRowView)this.BindingContext[this.ds,this.ds.Tables[0].TableName].Current;
Form2 form2 = new Form2(drv);
form2.ShowDialog(); }
private void dataGrid1_DoubleClick(object sender, System.EventArgs e)
{
button1_Click(button1,EventArgs.Empty);
}
}
}
//子窗体代码
=======================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace Zhzuo
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private DataRowView drv;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form2(DataRowView dr)
{
InitializeComponent();
this.drv = dr;
this.textBox1.Text = (string)drv["IpAddress"];
this.textBox2.Text = (string)drv["UserName"];
this.textBox3.Text = (string)drv["Password"];
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(28, 16);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 3;
this.textBox1.Text = "textBox1";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(28, 56);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 4;
this.textBox2.Text = "textBox2";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(28, 92);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 5;
this.textBox3.Text = "textBox3";
//
// button1
//
this.button1.Location = new System.Drawing.Point(152, 152);
this.button1.Name = "button1";
this.button1.TabIndex = 6;
this.button1.Text = "保存";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(236, 152);
this.button2.Name = "button2";
this.button2.TabIndex = 7;
this.button2.Text = "退出";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(324, 201);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false); }
#endregion private void button1_Click(object sender, System.EventArgs e)
{
drv["IpAddress"] = this.textBox1.Text;
drv["UserName"] = this.textBox2.Text;
drv["Password"] = this.textBox3.Text;
} private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx