Finally, I got time to blog another post on Real World Scenario. This time I received an email from a final year student. As mentioned earlier, the purpose of blogging about these issues is to share solution with others facing similar problem.
Scenario: (copied from email)
I’m facing some problems in my project. In one of the form I am using DataGridview to display my data… ! as mention in the attached JPEG. All columns are Databound. (except View Detail Column).
I want, when i click on ‘View’ all the data of particular row will display it new form im detail… ! Is it possible ??
The answer to this query is quite simple. DataGridView exposes an event ‘CellContentClick’ to which you can subscribe and handle the event. Consider the code snippet:
//subscribe the event first
this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick);
//handle the event
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 4) //4 is the index of Column with link (DataGridViewLinkColumn)
{
DetailForm detailForm = new DetailForm();
detailForm.ShowDialog();
}
}
and that will give you the desired functionality:) Thank you again for contacting me. If you have any issue related to .NET, send me an email and I will try my level best to solve the query for you.
5 Comments
liferockzzzz · September 7, 2009 at 6:18 pm
If I use Datalist in place of datagrid view in web application
so “cell content click ” event is also present in data list or I have to apply some other procedure Guide me
Adil Mughal · September 13, 2009 at 1:37 pm
@liferockzzzz: Can you please provide some details what you exactly want?
liferockzzzz · September 16, 2009 at 4:56 am
actually my project is of “online shopping cart”for displaying products I use Datalist and for showing details popup window will open the problem is I Didn’t know how to connects details with each product so on clicking on products its detail will show in pop up window?
daniel · April 3, 2015 at 5:25 am
SAP Training Courses in Chennai,
The modules in SAP Training are highly integrated in real-time, in the sense that information is shared across, and between the modules. Also, data integrity is maintained and errors are minimized as data is entered only once. Visit Us, SAP Training Courses in Chennai
Mohamed Omer · July 29, 2015 at 12:24 pm
Great and impressive article!
Seo Training in Chennai