ComboBoxの最長文字列の長さに基づいて、DataGridViewComboBoxColumnの長さを書式設定しようとしています。ここに私が現在持っているコードはありますが、コンボボックスの前の選択に基づいてDataGridViewComboBoxColumnの書式を設定するだけです。文字列の長さに基づくComboBoxの書式設定
DataGridViewComboBoxColumnをcomboBoxの最長文字列の長さにする方法はありますか?あなただけComboBox
で最も長い文字列を計算する必要があるよう
Private Sub comboTest_SelectionChangeCommitted(ByVal sender As Object, ByVal e As EventArgs) Handles comboTest.SelectionChangeCommitted
Dim senderComboBox As ComboBox = CType(sender, ComboBox)
'Change the length of the text box depending on what the user has
'selected and committed using the SelectionLength property.
If (comboTest.SelectionLength > 0) Then
comboTest.Width = comboTest.SelectionLength * CType(Me.comboTest.Font.SizeInPoints, Integer)
comboTest.SelectedValue = comboTest.SelectedText
End If
End Sub
美しい、病気 – user765942
これはうまくいくかもしれないことをしようとしますが、フォントが比例している場合にのみ。 – TheBlastOne
これは私のコードです:Dim length = 0それぞれのアイテムFor String in markCode.Items length = Max(length、item.Length)Next length> 0 then markCode.Width = length * CType(Me.markCode.Font.SizeInPoints 、Integer)markCode.SelectedValue = markCode.SelectedText End Ifここで受け取ったエラーは 'selectedValueはsystems.windows.forms.dataGridViewComboBoxColumのメンバーではありません。 – user765942