Home Forums WinForms controls Xceed Grid for WinForms C# doubleclick event question – please help!

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13293 |

    Hello,

    I just need to trigger some code when a double click is made in any row of the grid. I saw a post here but it need a loop… Is it realy need to loop to get a doubleclick event in the grids row? I find that kinda odd.

    Well I hope I can hear from anyone soon.

    Imported from legacy forums. Posted by EFileTahi-A (had 5857 views)

    User (Old forums)
    Member
    Post count: 23064

    You need the loop when you subscribe to the doubleClick event of each row.

    The loop is only executed once.

    Like this:

    //place this in a init method…
    foreach( Xceed.Grid.DataRow row in gridControl1.DataRows)
    {
    row.DoubleClick += new EventHandler(row_DoubleClick);
    }

    private void row_DoubleClick(object sender, EventArgs e)
    {
    MessageBox.Show(“row_DoubleClick”);
    }

    I think this is the only way. And it performs without problems.

    Regards
    Thomas

    Imported from legacy forums. Posted by C# (had 480 views)

    User (Old forums)
    Member
    Post count: 23064

    You don’t need the loop. If you use the loop, you have to do it each time the datarows are built. A better method is: subscribe the DoubleClick event of the DataRowTemplate. When the grid adds a new DataRow, that DataRow gets all the events of the template row.

    // init method
    myGridControl.DataRowTemplate.DoubleClick += new EventHandler(row_DoubleClick);

    private void row_DoubleClick(object sender, EventArgs e)
    {
    MessageBox.Show(“row_DoubleClick”);
    }

    Imported from legacy forums. Posted by Tommy (had 275 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you both for the replies, but tommy, where should I place the: myGridControl.DataRowTemplate.DoubleClick += new EventHandler(row_DoubleClick);
    ?

    Imported from legacy forums. Posted by EFileTahi-A (had 455 views)

    User (Old forums)
    Member
    Post count: 23064

    If you’re using the Visual Studio Forms Designer, you can select the DataRowTemplate in the grid on the form, go to the <b>Properties</b> panel, click on the <b>Events</b> button (the one with the lightning bolt), and double-click on the <b>DoubleClick</b> event.

    If you want to do it in code, it should be placed after you have created and initialized the grid. If the grid is initialized in the <b>InitializeComponent</b> method (if you use the Visual Designer), you can add the line in the constructor of your form, right after the line: <b>InitializeComponent();</b>

    Imported from legacy forums. Posted by Tommy (had 305 views)

    User (Old forums)
    Member
    Post count: 23064

    Am sorry tommy, is not the doubleclick event suppose to be trigger only when u double click on a grids empty space? Anyway, still did not understand what to do with the “lvwDB.DataRowTemplate.DoubleClick += new EventHandler(row_DoubleClick);” … Sorry for being such a moron 🙁

    Imported from legacy forums. Posted by EFileTahi-A (had 258 views)

    User (Old forums)
    Member
    Post count: 23064

    First, you’re not a moron.
    Second, maybe it’s better if you just do it in code.
    The constructor of your form should look like this:

    public myForm()
    {
    InitializeComponent();
    }

    You should add the DoubleClick-line after InitializeComponent, like this:

    public myForm()
    {
    InitializeComponent();
    <b>lvwDB.DataRowTemplate.DoubleClick += new EventHandler(row_DoubleClick);</b>
    }

    You should also add the method row_DoubleClick, that looks like this:

    private void row_DoubleClick(object sender, EventArgs e)
    {
    }

    Imported from legacy forums. Posted by Tommy (had 304 views)

    User (Old forums)
    Member
    Post count: 23064

    thank u tommy clarified now! 🙂

    Imported from legacy forums. Posted by EFileTahi-A (had 258 views)

    User (Old forums)
    Member
    Post count: 23064

    Well, I did understand what by the time I last posted on here, but, it seems that does not work tommy when I today try it.

    I added:

    public f_t_ListChoose()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();
    <b>lvwDB.DataRowTemplate.DoubleClick += new EventHandler(row_DoubleClick); </b>
    //
    // TODO: Add any constructor code after InitializeComponent call
    //
    }

    And I created the:

    private void row_DoubleClick(object sender, EventArgs e)
    {
    MessageBox.Show(“bla”);
    }

    But I cannot make it work 🙁

    Imported from legacy forums. Posted by EFileTahi-A (had 6809 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.