Ticket Q248641
Visible to All Users

How To Dynamically Format Columns For A Detail View

created 15 years ago

Hello
I have been using grids for a while, but now need to do a master-detail grid, and am a bit confused.
I normally load the data into a dataset, and assign this to the grids datasource. I can then set the column properties like this :
               // Get the columns collection
                GridColumnCollection objColumns = ((GridView)grdStock.MainView).Columns;
                // Fixed columns (in order they should first appear)
                ((GridColumn)objColumns["vchStockCode"]).Fixed = FixedStyle.Left;
                ((GridColumn)objColumns["vchStockName"]).Fixed = FixedStyle.Left;
                // Hide the columns we dont want to display
                objColumns["intStockID"].Visible = false;
                objColumns["vchDescription"].Visible = false;
                objColumns["intStockTypeID"].Visible = false;
                objColumns["tstTimeStamp"].Visible = false;
                ((GridColumn)objColumns["tstTimeStamp"]).OptionsColumn.ShowInCustomizationForm = false;
                ((GridColumn)objColumns["blnObsolete"]).Caption = "Obsolete";
                objColumns["blnObsolete"].Width = 70;
                ((GridColumn)objColumns["blnObsolete"]).VisibleIndex = 0;
                ((GridColumn)objColumns["vchStockCode"]).Caption = "Code";
                objColumns["vchStockCode"].Width = 120;
                ((GridColumn)objColumns["vchStockCode"]).VisibleIndex = 1;
                ((GridColumn)objColumns["vchStockName"]).Caption = "Name";
                objColumns["vchStockName"].Width = 140;
                ((GridColumn)objColumns["vchStockName"]).VisibleIndex = 2;
                ((GridColumn)objColumns["vchNominalCode"]).Caption = "Nominal Code";
                objColumns["vchNominalCode"].Width = 100;
For a master-detail I can use this apporach for the master, but have no idea how to do this for the detail grid. I have loaded data in the objGridView_MasterRowGetChildList event, and after reading about master-detail events set up the other needed events, and all works well so far. However I have no idea how to set the column properties dynamically ?
I have tried from within the objGridView_MasterRowGetChildList event, and also from the grdStockProducts_ViewRegistered event, but none seem to have any columns when I try this :
                GridColumnCollection objColumns = objCardView.Columns;
So there is nothing to configure.
Thank you

Show previous comments (4)
Anatol (DevExpress) 15 years ago

    Hello Stephen,
    I've attached a sample project, which demonstrates how to use the MasterRowExpanded event to customize the created detail view. Can this solution be applied in your situation?
    >> Also for the demos I cleaned the build and did a successful rebuild all, but still the same error on trying to see the form.
    There is a possibility that the problem occurs when converting the VS 2005 solution to VS 2008. Please refer to the ScheduleMainDemo.cs Fails to Compile Support Center issue.
    I've also attached the GridMainDemo and GridTutorials demos, installed on my machine. Please let me know whether it works well for you.
    Thanks,
    Anatol

    SW SW
    Stephen Winstanley_2 15 years ago

      Thank you for this, that example explains it perfectly and I can now configure the columns without needing to add them.
      I tried the demo again today and it is loading the forms correctly. I can only assume from this that compiling alone is not enough (even though I re-opened the forms) and a re-start is required after the compilation to get them to show.
      Thank you for your help.

      Anatol (DevExpress) 15 years ago

        You are always welcome.
        Thanks,
        Anatol

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.