私はDataGridViewから継承するコントロールを作成しています。私はコントロールのコンストラクタでプログラム的に列を追加しています。VB.NETカスタムDataGridViewコントロール - 実行時に列が重複していますか?
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
OptionsForm = New frmOptions(Me)
'NOTE: Add columns programmatically rather than via the designers properties window, or they will be duplicated when added to a form!
Dim colIpAddress, colPort, colStatus, colSpeed, colCountry As New DataGridViewTextBoxColumn
colIpAddress.HeaderText = "IP"
colPort.HeaderText = "Port"
colStatus.HeaderText = "Status"
colSpeed.HeaderText = "Speed"
colCountry.HeaderText = "Country"
Columns.AddRange({colIpAddress, colPort, colStatus, colSpeed, colCountry})
RowCount = 1
Me.Refresh()
End Sub
コントロールをフォームに追加すると、列が正しく表示されます。しかし、実行時に列が複製されます。 if文を追加して、現在のカラム数が0の場合にのみカラムが追加されるようにしました。
誰でも知っていることを知っていますか?ありがとう!列を追加し、唯一それがデザインモードでいた場合、それらを追加する前にチェックを追加することによって、この自分自身を修正
dataGridView1.AutoGenerateColumns = false;
すでにこれを試しても動作しません。しかし、ありがとう。 –