Multicolumn Combobox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mazintech
    New Member
    • May 2015
    • 10

    Multicolumn Combobox

    Hi Guys
    Can someone correct my code. I am trying to create a third column on a multicolumn combo box but the second column is overwritten with text from two columns (i.e. the second and third).

    Here is my Code:


    Code:
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'PolicyInfoDataSet.tblPolicy_Information' table. You can move, or remove it, as needed.
            Me.TblPolicy_InformationTableAdapter.Fill(Me.PolicyInfoDataSet.tblPolicy_Information)
            'TODO: This line of code loads data into the 'PolicyInfoDataSet.tblCall_Transactions' table. You can move, or remove it, as needed.
            Me.TblCall_TransactionsTableAdapter.Fill(Me.PolicyInfoDataSet.tblCall_Transactions)
    
            Dim Pol As DataTable = PolicyInfoDataSet.tblPolicy_Information
            PolicyNoComboBox.DataSource = Pol
            PolicyNoComboBox.DrawMode = DrawMode.OwnerDrawFixed
        End Sub
        Private Sub PolicyNoComboBox_DrawItem(sender As Object, e As System.Windows.Forms.DrawItemEventArgs) Handles PolicyNoComboBox.DrawItem
            ' Draw the default background
            e.DrawBackground()
    
            ' The ComboBox is bound to a DataTable,
            ' so the items are DataRowView objects.
            Dim drv As DataRowView = CType(PolicyNoComboBox.Items(e.Index), DataRowView)
    
            ' Retrieve the value of each column.
            Dim PolID As String = drv("ID").ToString()
            Dim PolNo As String = drv("Prosperity Policy No").ToString()
            Dim Tel As String = drv("Telephone Cell").ToString()
    
    
            '-----------------------------------------------------------------------------------------------------------------------
    
            ' Get the bounds for the first column
            Dim r1 As Rectangle = e.Bounds
            r1.Width = r1.Width / 3
    
            ' Draw the text on the first column
            Using sb As SolidBrush = New SolidBrush(e.ForeColor)
                e.Graphics.DrawString(PolID, e.Font, sb, r1)
            End Using
    
            ' Draw a line to isolate the columns 
            Using p As Pen = New Pen(Color.Black)
                e.Graphics.DrawLine(p, r1.Right, 0, r1.Right, r1.Bottom)
            End Using
    
            '---------------------------------------------------------------------------------------------------------------
    
            ' Get the bounds for the second column
            Dim r2 As Rectangle = e.Bounds
            r2.X = e.Bounds.Width / 3
            r2.Width = r2.Width / 2
    
            ' Draw the text on the second column
            Using sb As SolidBrush = New SolidBrush(e.ForeColor)
                e.Graphics.DrawString(PolNo, e.Font, sb, r2)
            End Using
    
            ' Draw a line to isolate the columns 
            Using p As Pen = New Pen(Color.Black)
                e.Graphics.DrawLine(p, r2.Right, 0, r2.Right, r1.Bottom)
            End Using
    
    
            '---------------------------------------------------------------------------------------------------------------
    
            ' Get the bounds for the third column
            Dim r3 As Rectangle = e.Bounds
            r3.X = e.Bounds.Width / 3
            r3.Width = r3.Width / 3
    
            ' Draw the text on the third column
            Using sb As SolidBrush = New SolidBrush(e.ForeColor)
                e.Graphics.DrawString(Tel, e.Font, sb, r3)
            End Using
    
            PolIDTextBox.Text = PolID
            PhoneNoTextBox.Text = Tel
        End Sub
Working...