ARTICLE

Using New ComboBox ActiveX With VB

Posted by Mostafa Kaisoun Articles | Visual Basic .NET November 19, 2012
This is my attempt to create a resizable ComboBox ActiveX to set its height to the height of a DataGrid cell.
Reader Level:
Download Files:
 

Introduction

When I create a project for using a DataGrid with a ComboBox, I hope to get a resizable ComboBox to set its height as the height of the DataGrid cell. This is my attempt to create a resizable ComboBox ActiveX, now I can change its height. Some programmers use a Form, ListBox, TextBox and a Button to create a ComboBox, but I am using a Panel, ComboBox, TextBox and a Button to create my ActiveX. Using a Panel to hide the upper part of the ComboBox and using this Panel as the container for the TextBox and Button.

About the Project of my ActiveX:

  • Name of the Project is: MKCombo
  • Name of UserControl is: KCombo
  • Name of Panel is: ComboHide
  • Name of ComboBox is: ComboCtrl
  • Name of TextBox is: ComboText
  • Name of Button is: ComboButton

After you expand the files: ComboVB.zip, you can open "SizableCombo" solution to read the code of my ActiveX in the "MKCombo" project and read the code to test the ActiveX in the "SizableCombo" project.
I tried to use "DataSource" to bind my ActiveX with data but I can't, so then I used another idea.

My ActiveX has:

  • Event: cmbSelectedChanged for SelectedIndexChanged event.
  • Property: cmbBorderStyle for BorderStyle property.
  • Property: cmbSelectedIndex for SelectedIndex property.
  • Property: cmbSelectedItem for SelectedItem property.
  • Property: cmbText for Text property.
  • Property: cmbItemsCount for Items.Count property.
  • Method: cmbAddItem for Items.Add method.
  • Method: cmbClear for Items.Clear method.

About the Code

Code to bind the ActiveX with data:

Public Sub cmbBindData(ByVal cmbSql As String, ByVal cmbCnn As OleDbConnection, ByVal cmbField As String)

    If (cmbCnn.State = ConnectionState.Open) Then cmbCnn.Close()

    cmbCnn.Open()

    Dim cmdReader As OleDbCommand = New OleDbCommand(cmbSql, cmbCnn)

    Dim datRdr As OleDbDataReader = cmdReader.ExecuteReader()

 

    ComboCtrl.Items.Clear()

    While (datRdr.Read())

       ComboCtrl.Items.Add(datRdr(cmbField))

    End While

   ComboCtrl.SelectedIndex = 0

End Sub

Remark

When the test project is executed, please resize any row to see how the ComboBox changes its height.

I hope this article is useful, If you have any idea, please tell me.

Login to add your contents and source code to this article
post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter