2011-09-30 3 views
0

SQL Server 데이터베이스의 데이터 집합 인 데이터 소스가있는 ComboBox가 있습니다..net의 데이터 집합과 연결된 콤보 상자의 열 너비 변경

열의 너비는 열 이름의 너비와 관련이 있습니다. 내용을 제대로보고 cuted하지 않기 위해 너비를 늘리고 싶습니다. 당신이 볼 수 있듯이

screenshot http://uploadpic.org/storage/2011/thumb_iDSwsbVfSB4mbWvR1xNmm98Fp.png

두 번째 열의 값이 completly 표시되지 않습니다 : 여기에

내가 무슨 말을하는지의 스크린 샷이다.

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

답변

1

로 번역하는 문제가 발생하지 무슨 말처럼 약 somehting : 내가 아는

Dim total As Integer = 0 
Dim maxLen As Integer = 0 
For Each row As DataRow In ds.Tables(0).Rows 
    total = 0 
    For Each Str As String In row.ItemArray 
    total = Str.Length + total 
    Next 
    If maxLen < total Then maxLen = total 
Next 

Combo.Width = maxLen + 5 

그것의 무차별 한 힘 그러나 당신은 가장 긴 항목을 발견하고 그 너비를 설정합니다. +5는 패딩을 위해 변경해야 할 수도 있습니다.

+0

신경 쓰지 마세요. 다시 귀하의 예제를 보면 나는 당신의 콤보 상자가 문자열의 목록을 포함하지 않는 것을 볼 수 있습니다. –

+0

올바른 방향으로 안내하기 위해 솔루션을 업데이트했습니다. itemArray가 문자열 객체에 올바르게 변환되는지 확실하지 않습니다. 이게 도움이되는지 알려주세요. –