I've a data grid that is bound to a pivoted dataset at runtime and no schema has been set as I don't know the columns to be included at design time as they vary depending on user selection / database config. The pivoted dataset is constructed from 3 datasets (columns, rows and values) and I have ensured that the ordering of the column in the constructed, pivoted, dataset are correct before binding. However, when bound, the grid re-orders the columns. I cannot determine what criteria is used for this. As far as I'm concerned the data grid columns should appear in the same order as they are in the dataset. I know that there is a mechanism to re-order but why is this happening at all? Properties set on my grid: - Me.UGResults.CausesValidation = False Me.UGResults.Cursor = System.Windows.Forms.Cursors.Default Me.UGResults.DisplayLayout.AutoFitColumns = True Me.UGResults.DisplayLayout.Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.No Me.UGResults.DisplayLayout.Override.AllowDelete = Infragistics.Win.DefaultableBoolean.[True] Me.UGResults.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.[True] Me.UGResults.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.[False] Me.UGResults.DisplayLayout.Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortSingle Me.UGResults.DisplayLayout.Override.SelectTypeRow = Infragistics.Win.UltraWinGrid.SelectType.[Single] Me.UGResults.Dock = System.Windows.Forms.DockStyle.Fill Me.UGResults.Location = New System.Drawing.Point(5, 5) Me.UGResults.Name = "UGResults" Me.UGResults.Size = New System.Drawing.Size(754, 102) Me.UGResults.TabIndex = 11
aim123 said:With regards to the code sample, I reiterate that this project uses pivoted data built from 3 separate datasets... columns, rows and values. The example provided uses the column data set and so each row actually represents a column. It is equivalent to looping through the columns on the pivoted dataset.
Ooh, I see. That makes sense, then.
Hi Mike, The issue is that the binding manager is re-ordering the columns. I have checked the pivoted dataset and the column order is correct. Hence the requirement to re-order. I would suggest that there is something unknown about the binding manager as I am relying on default behaviour. With regards to the code sample, I reiterate that this project uses pivoted data built from 3 separate datasets... columns, rows and values. The example provided uses the column data set and so each row actually represents a column. It is equivalent to looping through the columns on the pivoted dataset.
Well, what would you suggest? The grid shows the columns in the order that the BindingManager returns them. There's no other order the grid can use, since that's all it has access to.
Anyway, the code you have here is horribly inefficient. Why are you looping through every row in the data table? You are essentially setting the VisiblePosition repeatedly to the same value for every row of data. You only have to do this once and you should do it in the InitializeLayout event.
Yes thanks fixed with the following but I don't feel that this hould be required.
Private Sub setColumnOrder() 'Loop through all the columns and set Dim IntOrder As Integer = 0 For Each row As DataRow In DsColumnsByTestTypeIDForResultsForm1.Tables(0).Rows Me.UGResults.DisplayLayout.Bands(0).Columns(row.Item("Name")).Header.VisiblePosition = IntOrder IntOrder += 1 Next row End Sub
The grid gets the data structure (and thus the columns and their order) from the BindingManager. This is usually the same order as the columns int the data table and I have never seen it come out any other way, but if the order of the columns is not the same, it must be the BindingManager that is re-ordering them.
In any case, you have total control of the order of columns in the grid via the column.Header.VisiblePosition property. The InitializeLayout event is a good place to set this.