我有一个绑定到业务对象列表的DataGridView:
原文链接:https://www.f2er.com/vb/255599.htmlDim template As New IncidentTemplate Dim temps As List(Of IncidentTemplate) = template.LoadAll Dim bs As New BindingSource If Not temps Is Nothing Then bs.DataSource = temps Me.dgvTemplates.DataSource = bs End If
然后我添加一个未绑定的按钮列,并使一些绑定列不可见:
Dim BtnCol As New DataGridViewButtonColumn With BtnCol .Name = "Edit" .Text = "Edit" .HeaderText = String.Empty .ToolTipText = "Edit this Template" .UseColumnTextForButtonValue = True End With .Columns.Add(BtnCol) BtnCol = Nothing For Each col As DataGridViewColumn In Me.dgvTemplates.Columns Select Case col.Name Case "Name" col.DisplayIndex = 0 col.FillWeight = 100 col.Visible = True Case "Description" col.DisplayIndex = 1 col.FillWeight = 100 col.Visible = True Case "Created" col.DisplayIndex = 3 col.HeaderText = "Created On" col.DefaultCellStyle.Format = "d" col.FillWeight = 75 col.Visible = True Case "CreatedBy" col.DisplayIndex = 2 col.HeaderText = "Created By" col.FillWeight = 75 col.Visible = True Case "Edit" col.DisplayIndex = 4 col.HeaderText = "" col.FillWeight = 30 col.Visible = True Case Else col.Visible = False End Select Next
这似乎工作得相当好,除了我做的事情,按钮列(编辑)总是显示在其他列的中间而不是在结尾.我已经尝试了DGV.Columns.Add和DGV.Columns.Insert以及设置列的DisplayIndex(这适用于所有其他列)但我无法使按钮列显示在正确的位置.我也尝试在设置其余列之前和之后添加按钮列,但这似乎没有区别任何人都可以建议我做错了什么?这让我疯狂….