如何使用datagrid视图将datagrid视图中的单元格双击事件的所有记录显示到新的winform? [英] How to show all record on cell double click event in datagrid view to new winform using datagrid view?
问题描述
我有一个表名dbo.tblPSData,包含与6个不同实体相关的数字或记录。我在这里做的是为这6个不同的实体分配一个唯一的ID,如...
101-学校
102-运输
103 - 医院
104-功能
106-安全
这些实体包括否。记录和我使用datagrid视图来显示单个实体中存在的记录总数,如...
代码Service_Name Total_Records
101学校2336
102运输12006
103医院3876
104功能234
106安全性4576
现在我想要的是当我双击任何一行数据网格视图时加载一个新的窗体表格它显示了特定实体中存在的记录总数。
任何人都可以帮助我解决这个问题???? >
谢谢
I have a table name dbo.tblPSData consisting numbers or records related to 6 different entity. What i do here i assign a Unique ID to these 6 different entity like...
101-For Schools
102-Transports
103-Hospitals
104-Functions
106-Security
these entity consisting no. of records and i used datagrid view to show total number of records present in single entity like...
CODE Service_Name Total_Records
101 Schools 2336
102 Transport 12006
103 Hospital 3876
104 Function 234
106 Security 4576
Now what i want when i double click on any single row of datagrid view a new windows form loaded and it show me the total number of records present in particular entity.
ANY ONE HELP ME TO GETTING OUT OF THIS PROBLEM????
THANKS
推荐答案
首先,你必须在DataShowForm中创建属性
从主表单获取entityId
。
赞,
First of all, you have to create property inDataShowForm
to getentityId
from main form.
Like,
private string _id;
public string Id
{
get { return _id; }
set { _id = value; }
}
然后从主窗体llke处理 CellDoubleClick
事件:
Then handle CellDoubleClick
event from main form llke:
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
empid = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
DataShowForm frm = new DataShowForm();//Your DataShowForm
frm.Id = empid;//Asign value of Id property of DataShowForm
frm.Show();
}
然后,Write方法获取 DataShowForm
上的数据使用 Id
你从另一个表单中点击并从加载事件中调用它。
你不要就这个功能而言,根本不需要 RowEnter
事件。
Then, Write method to fetch data on DataShowForm
with use of Id
that you have clicked from another form and call it on from load event.
You don''t need RowEnter
event at all as far as this functionality is concern.
我想你正在搜索这个
i think you are searching for this
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
OleDbConnection con = new OleDbConnection("YourConnection");
con.Open();
DataSet ds;
ds= new DataSet();
OleDbCommand cmd = new OleDbCommand("select * from YourDetailTableName where id='" + dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()+"'", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
Form2 frm;
frm=new Form2();
frm.dataGridView1.DataSource = ds;
frm.ShowDialog();
}
在网格迭代事件中使用onclick事件并打开一个javascript窗口。
On grid itembound event use the onclick event and open a javascript window.
public void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton hlnkR =(LinkButton)e.Row.FindControl(hlnk);
hlnkRate.Attributes.Add(onClick,JavaScript:window.showModalDialog(''Popup.aspx?Agr =+ arg1 +'','''',''dialogWidth:1000px; dialogHeight:400px,scroll:1,center:1''); return false;);
}
}
LinkButton hlnkR = (LinkButton)e.Row.FindControl("hlnk");
hlnkRate.Attributes.Add("onClick", "JavaScript: window.showModalDialog(''Popup.aspx?Agr=" + arg1 + "'', '''', ''dialogWidth:1000px;dialogHeight:400px,scroll:1,center:1''); return false;");
}
}
这篇关于如何使用datagrid视图将datagrid视图中的单元格双击事件的所有记录显示到新的winform?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!