我想根據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