vb.net - riempimento - impianti di strippaggio




Combobox piatta multi-colonna: riempimento di colonne con tabelle DB (2)

Penso che manchi solo le istruzioni per mostrare le colonne. Dall'esempio:

 MtgcComboBox1.LoadingType = MTGCComboBox.CaricamentoCombo.DataTable
 MtgcComboBox1.SourceDataString =  {"Name", "SurName"}
 MtgcComboBox1.ColumnWidth = "100;100"
 MtgcComboBox1.SourceDataTable = dtb

Ho trovato una combobox multi-colonna gratuita molto buona, ma non posso riempire la seconda colonna con It, finora sono riuscito a visualizzare solo 1 colonna. Qualcuno ha esperienza nel fare questo tramite Datable? Deve essere fatto in questo modo, almeno l'auhors del controllo afferma così. Ecco il mio codice:

MODIFICARE:

      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

       Dim SQL As String = "SELECT Name,Surname from MyTable"

       Dim dtb As New DataTable
       dtb.Columns.Add("Name", System.Type.GetType("System.String"))
       dtb.Columns.Add("Surname, System.Type.GetType("System.String"))

       Using con As OracleConnection = New OracleConnection("Data Source=MyDB;User Id=Lucky;Password=MyPassword;")

                Try

                    con.Open()

                    Using dad As New OracleDataAdapter(SQL, con)
                        dad.Fill(dtb)

                    End Using

                    MtgcComboBox1.ColumnNum = 2
                    MtgcComboBox1.LoadingType = MTGCComboBox.CaricamentoCombo.DataTable
                    MtgcComboBox1.SourceDataString = {"Name", "Surname"}
                    MtgcComboBox1.SourceDataTable = dtb

                    con.Close()

                Catch ex As Exception
                    'MessageBox.Show(ex.Message)
                Finally
                    con.Dispose()
                End Try

        End Using

Ed ecco il link per il controllo - alcune istruzioni anche qui: http://www.codeproject.com/Articles/8619/Flat-MultiColumn-Combobox-with-Autocomplete


Questa è la versione semplificata della risposta in qualsiasi modo per una casella combinata con 2 valori per riga?

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim dtb As New DataTable
    Using dad As New OracleDataAdapter("SELECT Name,Surname from MyTable", "Data Source=MyDB;User Id=Lucky;Password=MyPassword;")
        dad.Fill(dtb) ' this should add the columns
    End Using

    Dim items = From r In dtb.Rows.Cast(Of DataRow) r(0).ToString & vbNullChar & r(1).ToString
    ComboBox1.DrawMode = DrawMode.OwnerDrawFixed
    ComboBox1.DataSource = items.ToList
    'ComboBox1.DisplayMember = "Name"
    'ComboBox1.ValueMember = "Surname"
End Sub

Private Sub ComboBox1_DrawItem(sender As Object, e As DrawItemEventArgs) Handles ComboBox1.DrawItem
    e.DrawBackground() ' Fill the background.
    Dim items = ComboBox1.Items(e.Index).ToString.Split(ControlChars.NullChar) ' Extract the Record object corresponding to the combobox item to be drawn.
    Dim loc = e.Bounds.Location, xMid = (loc.X + e.Bounds.Width - loc.X) \ 2 ' Calculate important positions based on the area of the drop-down box.

    TextRenderer.DrawText(e.Graphics, items(0), e.Font, loc, e.ForeColor) ' Draw the first (Unique ID) string in the first half.
    TextRenderer.DrawText(e.Graphics, items(1), e.Font, New Point(xMid + 5, loc.Y), e.ForeColor) ' Draw the second (Name) string in the second half, adding a bit of padding.

    e.Graphics.DrawLine(SystemPens.ButtonFace, xMid, loc.Y, xMid, loc.Y + e.Bounds.Height) ' optional Draw the column separator line right down the middle.
    e.DrawFocusRectangle()        ' Finally, draw the focus rectangle.
End Sub