none
DataGridViewTextBoxCell and custom events RRS feed

  • General discussion

  • Hi,

     

    I have overridden the onPaint event in a class which inherits from the DataGridViewTextBoxCell so that I can create my own custom cell when it's displayed.  I need to raise an event from the cell and have done the following in my custom column class which inherits from the DataGridViewColumn...

     

    Code Snippet

     

        public class Class1 : DataGridViewColumn  
        {   
            public Class1 () : base(new MyDataGridViewTextBoxCell())  
            {  
                // Vars.  
                CustomCell cell = new CustomCell ();  
     
                // Add our event listener.  
                cell.DragButtonClicked += new DragButtonClickedEventHandler(cell_DragButtonClicked);  
     
                // Init.  
                CellTemplate = cell;  
            }   
      
            public void cell_DragButtonClicked(object sender, DragButtonsEventArgs e)  
            {  
                throw new NotImplementedException();  
            }  
        }

     

     

    However, the event is never fired because it is always null, despite my assigning it in the constructor.

     

    Does anyone have any ideas?

     

    I haven't used the "How to: Host Controls in Windows Forms DataGridView Cells" example because it only contains an example for editing mode and not just display mode.

     

    Thanks,
    Paul.

    Tuesday, August 26, 2008 8:36 AM

All replies

  • Hi mcdave

     

    I have read your thread and have some question on your issue.

    What is “DragButtonClicked” event mean, is it your custom event?

    If it is your custom event, how you fire them in your code?

     

    Base on my understanding, you want to create your own CustomCell inherited from DataGridViewCell, in your CustomCell, you have create a custom event named “DragButtonClicked”. So I want to know how you decide to fire this event and what’s your code write to fire it.

     

    Sincerely,

    Kira Qian

     

    Windows Forms General FAQs
    Windows Forms Data Controls and Databinding FAQs

    Friday, August 29, 2008 8:12 AM
  • We are changing the issue type to “Comment” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by editing your initial post and changing the radio button at the top of the post editor window. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions. Thank you!

    Best Regards

    Kira Qian

    Monday, September 1, 2008 8:59 AM
  • Hi Kira Qian,

     

    Thanks for your reply.

     

    You are correct in what you say in your first response.  DragButtonClicked is fired when the mouse cursor goes over a certain section on each cell.

     

    I don't know why the event was never fired but I worked around it by creating my own DataGridView and casting the .DataGridView method in each cell to my custom DataGridView and called a custom method.

     

    Not a great way of doing it, but it works.

     

    Ta,

    Paul.

    Tuesday, September 2, 2008 9:54 AM
  • Hi mcdave

     

    Since DragButtonClicked is your custom event, you should fire it by yourself in your code. I just wonder how you fire it.

    When you create a custom event, you should call the delegate to invoke each method the delegate pointed.

     

    Sincerely,

    Kira Qian

    Tuesday, September 2, 2008 10:14 AM
  • Hi,

     

    Thanks for your reply.  I have some pseudo code which might help...

     

    Code Snippet

    if(mouseOver)
    {
     if(DragButtonClicked != null)
     {
      DragButtonClicked(this, new DragButtonClickEventArgs(true));
     }
    }
    else
    {
     if(DragButtonClicked != null)
     {
      DragButtonClicked(this, new DragButtonClickEventArgs(false));
     }
    }

     

     

    DragButtonClicked is always null despite attaching listeners.

     

    Cheers,

    Paul.

    Friday, September 5, 2008 10:43 AM