如何使用datagrid视图在datagrid视图中将单元格双击事件的记录显示到新的winform? [英] How to show records on cell double click event in datagrid view to new winform using datagrid view?

查看:65
本文介绍了如何使用datagrid视图在datagrid视图中将单元格双击事件的记录显示到新的winform?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表名dbo.tblPSData,包含与6个不同实体相关的数字或记录。我在这里做的是为这6个不同的实体分配一个唯一的ID,如...

101-学校

102-运输

103 - 医院

104-功能

106-安全



这些实体包括否。记录和我使用datagrid视图显示特定日期在单个实体中输入的记录总数...



代码Service_Name日期Total_Records_Enter



101学校14-03-2011 36

102运输16-03-2011 126

103医院16-03-2011 76

104功能18-02-2011 23

106安全12-04-2011 46



现在是什么我想要当我双击任何一行数据网格视图时加载一个新的窗体表格,它会显示在实体的gridview中显示的特定日期输入的记录总数。



更新:

 私人 字符串 _ID; 
public string ID
{
get { return _id; }
set {_ id = value ; }
}
private DateTime dt;
public DateTime _dt
{
get { return dt; }
set {dt = value ;}
}
< span class =code-keyword> private void DataShowForm_Load( object sender,EventArgs e )
{
string s;
SqlConnection con = new SqlConnection( data source = ASHU-PC; initial catalog = login; integrated Security = true);
SqlDataAdapter adp = new SqlDataAdapter( select *来自tblPSData,其中code_id =' + _id + '和SDate =' + _dt + 'order by serial_no,con);
DataSet ds = new DataSet();
adp.Fill(ds, tm);(此行附带异常< span class =code-string> 将char数据类型转换为日期时间数据类型会导致日期时间值超出范围。
dataGridView1.DataSource = ds.Tables [ tm];
}





我要做什么?

帮助





谢谢

解决方案

我可以看到你正在尝试在 DataGridView.CellClick事件 [ ^ ]。最好的方法是更改​​Form2的构造函数以接受id值,并在构造时处理它。您可以根据Form1传递的ID在Form2上显示详细信息。



替代方案:在表单之间传递数据 [ ^ ]





- Amit

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 enter in single entity on particular date...

CODE Service_Name Date Total_Records_Enter

101 Schools 14-03-2011 36
102 Transport 16-03-2011 126
103 Hospital 16-03-2011 76
104 Function 18-02-2011 23
106 Security 12-04-2011 46

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 enter on particular date show in gridview on entity.

UPDATE:

private string _id;
        public string Id
        {
            get { return _id; }
            set { _id = value; }
        }
        private DateTime dt;
        public DateTime _dt
        {
            get { return dt; }
            set{dt=value;}
        }
        private void DataShowForm_Load(object sender, EventArgs e)
        {
            string s;
            SqlConnection con = new SqlConnection("data source=ASHU-PC;initial catalog=login;integrated Security=true");
            SqlDataAdapter adp = new SqlDataAdapter("select * from tblPSData where code_id='" + _id + "' and SDate='"+_dt+"' order by serial_no", con);
            DataSet ds = new DataSet();
            adp.Fill(ds,"tm");(This line came with exception "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.")
            dataGridView1.DataSource = ds.Tables["tm"];
        }



what i have to do ???
HELP


THANKS

解决方案

As I can see you are trying to open a new form(say Form2) on the DataGridView.CellClick Event[^]. The best way is to change the constructor of Form2 to accept the id value, and process it as it is constructed. You can show the details on Form2 based on the ID passed by Form1.

Alternatives : Passing Data Between Forms[^]


--Amit


这篇关于如何使用datagrid视图在datagrid视图中将单元格双击事件的记录显示到新的winform?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆