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
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.
Hi Stephen,
We suggest that you use the MasterRowGetLevelDefaultView event to create and provide Views for specific master-detail relationships. This event occurs before a specific master row is expanded.
For more information, please see the Master-Detail: Using Events and the How to configure detail grid views Knowledge Base article.
If you need any further assistance on this subject, please feel free to reactivate this ticket.
Thanks
Dimitros
I always have problems with the demos, that make them a bit useless for me. When I try to view any of the forms I always get this error from the designer :
The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: GridRunTimeUsing --- The base class 'DevExpress.XtraGrid.Demos.Tutorials.TutorialControl' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.
I also cannot seemt o find this TutorialControl to add a reference to it. Not sure why this happens as I only open the projects from the Start menu, maybe its the project converter that does it ?
Anyway from looking at the code, it seems you need to define the columns for detail views, and they do not 'pick up' on columns from the data as per the master grid (see my exmaple above where the columns are known from the data). Is this correct as it is much preferred for the column types to come from the datasource ?
I have looked at the //"Orders" gridview section which adds columns dependent on what exists in the table, but how do you deal with data types doing it this way. Hopefully you will tell me that the columns can be found from the data and I just need to change the captions ?
Hello Stephen,
Columns are already created, when the MasterRowExpanded event occurs. Please try to use this event to customize them as you require, and let me know whether this solution meets your needs.
>> I always have problems with the demos…
A similar question was asked in the Can't load demo thread. As far as I understand, the suggestion to rebuild demos was helpful. Please try to use the proposed solution and let me know if it helps.
Thanks,
Anatol
I seem to have managed to get it to work using this approach :
GridColumn objCol;
CardView objCards;
// Start the update
grdStockProducts.BeginUpdate();
// Get the card view
objCards = grdStockProducts.LevelTree.Nodes["Stores"].LevelTemplate as CardView;
// Get the columns collection
GridColumnCollection objColumns = objCards.Columns;
// Add the columns
objCol = objCards.Columns.Add();
objCol.FieldName = "blnObsolete";
objCol.Caption = "Obsolete";
objCol.VisibleIndex = 0;
objCol = objCards.Columns.Add();
objCol.FieldName = "vchStockCode";
objCol.Caption = "Code";
objCol.VisibleIndex = 1;
objCol = objCards.Columns.Add();
objCol.FieldName = "vchStockName";
objCol.Caption = "Name";
objCol.VisibleIndex = 2;
objCol = objCards.Columns.Add();
objCol.FieldName = "tstTimeStamp";
objCol.Caption = "tstTimeStamp";
objCol.Visible = false;
((GridColumn)objCol).OptionsColumn.ShowInCustomizationForm = false;
// End the update
grdStockProducts.EndUpdate();
However this does seem to need to create the columns which is at odds with your statement about them being already created, but is the same approach as the tutorial uses, so am I missing something ?
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. Maybe its the fact they install into the ProgramFiles directory and Windows 7 nags for elevated permissions because of this ? Anyway not to worry I have never been able to use them so its not a big loss, just annoying they dont work 'out of the box'.
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
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.
You are always welcome.
Thanks,
Anatol