更改与 .net 中的数据集关联的组合框中的列宽
我有一个 ComboBox,其数据源是来自 SQL Server 数据库的数据集。
其列的宽度与列名称的宽度相关。我想增加宽度,以便正确查看内容而不是被剪切。
这是我正在谈论的内容的屏幕截图:
正如您所看到的,第二列中的值并未完全显示。
这是我用来加载组合框的方法:
Public Sub CargarComboAlternativo(ByVal Combo As ComboBox, ByVal query As String)
Dim connectionString As String = "Data Source=" & Servidor & ";Database=" & Bdatos & ";Trusted_Connection=Yes;UID=" & UID & ";"
Dim adapter As SqlDataAdapter
Dim dataSet As DataSet = New DataSet()
Try
Using conn As SqlConnection = New SqlConnection(connectionString)
Using command As New SqlCommand(query, conn)
command.CommandType = CommandType.Text
conn.Open()
adapter = New SqlDataAdapter(command)
dataSet.Clear()
adapter.Fill(dataSet)
Combo.DataSource = dataSet
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
有什么建议吗?
我完全不介意 C# 中的建议,将其转换为 vb.net 不会有问题
I have a ComboBox with its datasource being a dataset from a SQL Server database.
The width of its columns are relative to the width of the name of the columns. I would like to increase that width in order to see the content properly and not cuted.
Here is a screenshot of what I'm talking about:
As you can see the values in the second column do not appear completly.
Here is the method I use to load a ComboBox:
Public Sub CargarComboAlternativo(ByVal Combo As ComboBox, ByVal query As String)
Dim connectionString As String = "Data Source=" & Servidor & ";Database=" & Bdatos & ";Trusted_Connection=Yes;UID=" & UID & ";"
Dim adapter As SqlDataAdapter
Dim dataSet As DataSet = New DataSet()
Try
Using conn As SqlConnection = New SqlConnection(connectionString)
Using command As New SqlCommand(query, conn)
command.CommandType = CommandType.Text
conn.Open()
adapter = New SqlDataAdapter(command)
dataSet.Clear()
adapter.Fill(dataSet)
Combo.DataSource = dataSet
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Any suggestions?
I don't mind at all a suggestion in C#, I won't have problems to translate it to vb.net
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后怎么样:
我知道它的蛮力,但你会找到最长的项目并将宽度设置为该值。 +5 用于填充,您可能需要更改它。
what about somehting like at the end:
I know its brute force but you'll find the longest item and set the width to that. the +5 is for padding you may need to change that.