Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Comments
Mayur Panchal 28-May-13 1:58am    
Do you want to show all the records related to clicked entity or only count ?
ashu_dhiman 28-May-13 2:05am    
i want to show all the records present in entity on double click event....
Mayur Panchal 28-May-13 2:18am    
and all those records are present on your current form or you will fetch those records when you load another form.?
ashu_dhiman 28-May-13 2:27am    
No current form shows the entity code, entity name, and total number of record present in particular entity in datagrid view. And i want to fetch all the record from table dbo.tblPSData when a double click on particular Entity Row. For e.g when i doubleclick entity row who's code is 102, a new winform loaded and show all the records whose entity code is 102 from table dbo.tblPSData present in data base.
Mayur Panchal 28-May-13 2:33am    
Plz show your code of, when you are double clicking on cell and opening new form. So i can suggest you.

First of all, you have to create property in DataShowForm to get entityId from main form.
Like,
C#
private string _id;
public string Id
{
    get { return _id; }
    set { _id = value; }
}


Then handle CellDoubleClick event from main form llke:
C#
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();
}


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.
 
Share this answer
 
v4
i think you are searching for this
C#
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();

        }
 
Share this answer
 
On grid itembound event use the onclick event and open a javascript window.

C#
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;");
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900