By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,335 Members | 2,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,335 IT Pros & Developers. It's quick & easy.

Multicolumn Combobox

P: 10
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:


Expand|Select|Wrap|Line Numbers
  1.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  2.         'TODO: This line of code loads data into the 'PolicyInfoDataSet.tblPolicy_Information' table. You can move, or remove it, as needed.
  3.         Me.TblPolicy_InformationTableAdapter.Fill(Me.PolicyInfoDataSet.tblPolicy_Information)
  4.         'TODO: This line of code loads data into the 'PolicyInfoDataSet.tblCall_Transactions' table. You can move, or remove it, as needed.
  5.         Me.TblCall_TransactionsTableAdapter.Fill(Me.PolicyInfoDataSet.tblCall_Transactions)
  6.  
  7.         Dim Pol As DataTable = PolicyInfoDataSet.tblPolicy_Information
  8.         PolicyNoComboBox.DataSource = Pol
  9.         PolicyNoComboBox.DrawMode = DrawMode.OwnerDrawFixed
  10.     End Sub
  11.     Private Sub PolicyNoComboBox_DrawItem(sender As Object, e As System.Windows.Forms.DrawItemEventArgs) Handles PolicyNoComboBox.DrawItem
  12.         ' Draw the default background
  13.         e.DrawBackground()
  14.  
  15.         ' The ComboBox is bound to a DataTable,
  16.         ' so the items are DataRowView objects.
  17.         Dim drv As DataRowView = CType(PolicyNoComboBox.Items(e.Index), DataRowView)
  18.  
  19.         ' Retrieve the value of each column.
  20.         Dim PolID As String = drv("ID").ToString()
  21.         Dim PolNo As String = drv("Prosperity Policy No").ToString()
  22.         Dim Tel As String = drv("Telephone Cell").ToString()
  23.  
  24.  
  25.         '-----------------------------------------------------------------------------------------------------------------------
  26.  
  27.         ' Get the bounds for the first column
  28.         Dim r1 As Rectangle = e.Bounds
  29.         r1.Width = r1.Width / 3
  30.  
  31.         ' Draw the text on the first column
  32.         Using sb As SolidBrush = New SolidBrush(e.ForeColor)
  33.             e.Graphics.DrawString(PolID, e.Font, sb, r1)
  34.         End Using
  35.  
  36.         ' Draw a line to isolate the columns 
  37.         Using p As Pen = New Pen(Color.Black)
  38.             e.Graphics.DrawLine(p, r1.Right, 0, r1.Right, r1.Bottom)
  39.         End Using
  40.  
  41.         '---------------------------------------------------------------------------------------------------------------
  42.  
  43.         ' Get the bounds for the second column
  44.         Dim r2 As Rectangle = e.Bounds
  45.         r2.X = e.Bounds.Width / 3
  46.         r2.Width = r2.Width / 2
  47.  
  48.         ' Draw the text on the second column
  49.         Using sb As SolidBrush = New SolidBrush(e.ForeColor)
  50.             e.Graphics.DrawString(PolNo, e.Font, sb, r2)
  51.         End Using
  52.  
  53.         ' Draw a line to isolate the columns 
  54.         Using p As Pen = New Pen(Color.Black)
  55.             e.Graphics.DrawLine(p, r2.Right, 0, r2.Right, r1.Bottom)
  56.         End Using
  57.  
  58.  
  59.         '---------------------------------------------------------------------------------------------------------------
  60.  
  61.         ' Get the bounds for the third column
  62.         Dim r3 As Rectangle = e.Bounds
  63.         r3.X = e.Bounds.Width / 3
  64.         r3.Width = r3.Width / 3
  65.  
  66.         ' Draw the text on the third column
  67.         Using sb As SolidBrush = New SolidBrush(e.ForeColor)
  68.             e.Graphics.DrawString(Tel, e.Font, sb, r3)
  69.         End Using
  70.  
  71.         PolIDTextBox.Text = PolID
  72.         PhoneNoTextBox.Text = Tel
  73.     End Sub
May 29 '15 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.