我想根据comboBox中最长字符串的长度来格式化DataGridViewComboBoxColumn的长度。这是我目前拥有的代码,但它仅基于用户在comboBox中的先前选择格式化DataGridViewComboBoxColumn。基于字符串长度的格式化组合框
有没有办法让DataGridViewComboBoxColumn在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 Each item As String In markCode.Items length = Max(length,item.Length)Next如果length> 0那么markCode.Width = length * CType(Me.markCode.Font.SizeInPoints ,整数)markCode.SelectedValue = markCode.SelectedText End If这里接收到的错误是'selectedValue不是systems.windows.forms.dataGridViewComboBoxColum的成员'任何想法? – user765942