I have a WinForm with a DataGridView set to read-only. When the user double-clicks on a row (cell) I want to display a form in which the full details for the selected Row are shown.
But the CellDoubleClick Event is not firing. Somewhere on the web i've read that the event doesn't work when DataGridView is set to read-only
, but even inserting a new DataGridView with default settings in MS Visual Studio doesn't help.
For Testing I used a sample code from MSDN, but the MessageBox doesn't open.
Here's my full Code:
Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace Projektmanager
{
public partial class Projektmanager : Form
{
// Declare MySQL Connection
private MySqlConnection connection;
public Projektmanager()
{
InitializeComponent();
if (this.OpenConn() == true)
{
string sql = "select Name as 'Auftragsnummer', Projektnummer, Gruppe as 'G-Nr.', (select name from Groups where NR=stdjobs.Gruppe limit 1) as 'Gruppe', Händler, Kunde, Land from stdjobs where NR like 'A%' order by NR desc;";
MySqlDataAdapter MSDA = new MySqlDataAdapter(sql, connection);
DataSet DS1 = new DataSet();
MSDA.Fill(DS1);
dataGridView1.DataSource = DS1.Tables[0];
this.CloseConn();
}
}
// open MySQL Connection Function
private bool OpenConn()
{
// Some Stuff
}
//Close MySQL connection Function
private bool CloseConn()
{
// More Stuff
}
private void beendenToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void refresh_DGV4()
{
// Much more Stuff
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
refresh_DGV4();
}
private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
{
refresh_DGV4();
}
private void DataGridView1_CellDoubleClick(Object sender, DataGridViewCellEventArgs e)
{
System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "ColumnIndex", e.ColumnIndex);
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex);
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "CellDoubleClick Event");
}
}
}
Can anyone tell me why the Event isn't recognized?
dataGridView1.CellDoubleClick += DataGridView1_CellDoubleClick;
ordataGridView1.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(DataGridView1_CellDoubleClick);
? – OhBeWise