none
Does Datagridview's onhandlecreated event have access to private members set in the constructor? RRS feed

  • Question

  • I have a custom datagridview and the code in the onhandlecreated event handler does not seem to be able to access private members set in the constructor. Whenever I attempt to get in there and use the private members (that are quite definitely set in the constructor) they are null.

    I am using this handler to get my data, filter the rows and then juggle the data into the grid in a very specific format, I'd be ok with using a different event if there's one that suits my purpose better. 

    Please help, I'm under a deadline and have been stuck for hours with no useful hits.


    Always keep searching and hoping. The minute you stop moving, you start dying.


    Wednesday, June 27, 2012 3:44 PM

Answers

  • SOLVED!

    the problem was that the designer was instantiating the control with a null argument to the filters. the cleanest fix I could figure out was to instantiate the custom grid from the form's constructor and set the design options at run time. 


    Always keep searching and hoping. The minute you stop moving, you start dying.

    • Marked as answer by CodeNinjaYoda Wednesday, June 27, 2012 5:09 PM
    Wednesday, June 27, 2012 5:09 PM

All replies

  • It really hard to follow you. Would it possible for you to post the code ?

    Regards

    Nairs

    Wednesday, June 27, 2012 4:26 PM
  • Stripped down code:

      

    public partial class CustomGrid : DataGridView { private FilterSaveData filters; public CustomGrid (FilterSaveData StartFilters) : base() { this.filters = new FilterSaveData(); this.filters = StartFilters; } protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); /** bunch of stuff that does not touch internal variable, basically loading datatables from dataset etc.. **/ if (this.filters.Opportunities.Length > 0) { /** apply custom rowfilter to datatable **/ } }

    the issue is that this.filters is null. 

    Always keep searching and hoping. The minute you stop moving, you start dying.


    Wednesday, June 27, 2012 4:32 PM
  • SOLVED!

    the problem was that the designer was instantiating the control with a null argument to the filters. the cleanest fix I could figure out was to instantiate the custom grid from the form's constructor and set the design options at run time. 


    Always keep searching and hoping. The minute you stop moving, you start dying.

    • Marked as answer by CodeNinjaYoda Wednesday, June 27, 2012 5:09 PM
    Wednesday, June 27, 2012 5:09 PM