2015-09-21 85 views
1

我通過Visual Studio表/列集合編輯器設置了一些數據表。不幸的是,似乎MS沒有包括任何方式來重新排序集合編輯器中的數據列,一旦你完成(沒有加/減設施)。因此,我不得不以編程方式重新排序我的列(在集合中亂序)。displayindex datatable/dgv列不工作

做了很多關於這個和我的生活的閱讀,找不到問題的根源。基本上,儘管下面的代碼,datacolumns仍然在datagridview上亂序顯示。代碼(摘要):

Private Sub LoadTextStylesDGV() 
    With _TextStylesDGV 
     .DefaultCellStyle.Padding = New Padding(0, 5, 0, 5) 
     .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells 
     .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells 
     .AllowUserToAddRows = False 
     .AllowUserToDeleteRows = False 
     .AllowUserToResizeColumns = True 

     .Columns.Add(New DataGridViewComboBoxColumn With {.DataPropertyName = "TextAlign", .Visible = True, 
               .Name = "TextAlign", 
              .HeaderText = "TextAlign", 
               .DataSource = MarqueeEditor._EnumDDContentAlign, 
               .FlatStyle = FlatStyle.Flat, 
               .AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells}) 
' And other column setups similar to above 
' .... 
    .DataSource = Global.CPWBAdmin.MarqueeEditor.MarqueeData.Tables("TextStyles") 
     .MultiSelect = False 
     .AllowUserToDeleteRows = False 

     With .Columns("ID") 
      .ReadOnly = True 
      .DefaultCellStyle.BackColor = Color.LightGray 
      .Visible = False 
      .DisplayIndex = 0 
      .Frozen = True 
     End With 

     With .Columns("Name") 
      .DisplayIndex = 1 
      .Frozen = True 
      .DefaultCellStyle.BackColor = Color.Linen 
     End With 

     .Columns("RandomStyle?").DisplayIndex = 2 

     With .Columns("Font") 
      .ReadOnly = True 
      .DefaultCellStyle.BackColor = Color.LightBlue 
      .AutoSizeMode = DataGridViewAutoSizeColumnMode.None 
      .DisplayIndex = 3 
     End With 

'.... other column display index settings 

    .Columns("Stroke3LineJoin").DisplayIndex = 49 
     .Columns("Stroke3Wrap").DisplayIndex = 50 
     .Columns("TextAutoFit").DisplayIndex = 51 
     'Sort: 
     .Sort(_TextStylesDGV.Columns("Name"), System.ComponentModel.ListSortDirection.Ascending) 
    End With 
End Sub 

我想知道DGV列是否在代碼的其他地方重新排序。當然 - 沒有辦法像在表演前一樣逐步調試。已經瀏覽了代碼,但看不到任何明顯的東西。有沒有人有任何想法,因爲這一個正在殺死我!如果只有MS允許列收集重新排序。 。:(

回答

0

Oooops沒有搜索不夠努力終於找到了解決辦法:

dgvReservedStalls.AutoGenerateColumns = True 
dgvReservedStalls.DataSource = clsReservedStalls.LoadDataTable() 
dgvReservedStalls.AutoGenerateColumns = False 

自動生成從DT列,然後釋放它重新排序的列有點晦澀難懂,MS。 ... :)

From here