扁平多列组合框 - 用DB表填充列 [英] Flat multi-column combobox - filling columns with DB tables
本文介绍了扁平多列组合框 - 用DB表填充列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现一个非常好的免费多列组合框,但不能填充第二列与它,到目前为止我设法只显示1列。任何人都有任何经验,通过Datable这样做 - 它必须这样做,至少控制权的索赔。这是我的代码:
I found a very good free multi-column combobox, but can't fill second column with It, so far I managed to display only 1 column. Does anybody have any experience doing this via Datable - It has to be done like this, at least auhors of control claim so. Here is my code:
编辑:
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
这里是控制链接 - 还有:
http://www.codeproject。 com / Articles / 8619 / Flat-MultiColumn-Combobox-with-Autocomplete
And here is link for control - some instructions there too : http://www.codeproject.com/Articles/8619/Flat-MultiColumn-Combobox-with-Autocomplete
推荐答案
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
这篇关于扁平多列组合框 - 用DB表填充列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文