Ok, I am trying to to make a double-click action when you click on a cell or row, within a dataGridView. The end goal is to have the single click select the whole row so that when you double-click any cell in the row it will load that row into a separate dataGridView.

I have searched and found this:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellcontentdoubleclick.aspx

But I cant figure out how to use it, even to just do the messagebox that it includes in it.

Any ideas? This is driving me crazy. I am running a stripped down test program before loading it in my main one. Here is the code for that. It just has a button to open a file browser. A textbox to load the file path into, a button to launch the file data into the first dataGridView, and an extra dataGridView. Thank you for all of your help!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = "C# Corner Open File Dialog";
            fdlg.InitialDirectory = @"c:\";
            fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
            fdlg.FilterIndex = 2;
            fdlg.RestoreDirectory = true;
            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                string listLocation = fdlg.FileName;
                textBox1.Text = fdlg.FileName;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = null;

            XmlDataDocument xmldataHQ = new XmlDataDocument();
            xmldataHQ.DataSet.ReadXml(textBox1.Text);
            DataSet dsHQ = new DataSet("Stats");
            dsHQ = xmldataHQ.DataSet;
            dataGridView1.DataSource = dsHQ.DefaultViewManager;
            dataGridView1.DataMember = "StatVal";
        }

       
        

       
  private void Form1_Load(object sender, EventArgs e)
      
        {

        }
    
    }
}

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

You could create event CellMouseDoubleClick or ColumnHeaderMouseDoubleClick in property editor and event page

aspx is related to web forms I think.

Hope this helps

Do not see directly what you have trouble with :
The example you give just constructs a string with Rowindex and ColumnIndex data which it gets from the e parameter which is of type DataGridViewCellEventArgs . Then this string is displayed in the MessageBox.

I am trying to create an event that will make it so that when any cell in dataGridView1 is double-clicked, it will run;

XmlDataDocument xmldataHQ = new XmlDataDocument();
xmldataHQ.DataSet.ReadXml(textBox1.Text);
DataSet dsHQ = new DataSet("Stats");
dsHQ = xmldataHQ.DataSet;
dataGridView2.DataSource = dsHQ.DefaultViewManager;
dataGridView2.DataMember = "StatVal";

In order to load xml file into a second dataGridView. The eventual hope is to make a single click select the row, and when double clicked, have just that row sent to a second dataGridView.

Not sure if that makes any sense.

Thanks for the replies

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

This is fairly easy to achieve. You can use the CellContentClick and CellContentDoubleClick events.

Check my tutorial to see how to create the event handlers correctly. You will probably find it easier to use the method shown in the image at the bottom of the tutorial :)

Edited 6 Years Ago by Geekitygeek: n/a

This is fairly easy to achieve. You can use the CellContentClick and CellContentDoubleClick events.

Thanks. I just started C# a few days ago, and didnt even notice that event button. You are awesome.

-Solved.

Thats why i wrote the tutorial...there are frequent posts from newbies who have typed out the code for an event handler without actually registering it.

Glad it helped, and mahalo for the compliment ;)

This question has already been answered. Start a new discussion instead.