property ComboBox.DataSource as Object

Retrieves or sets a value that indicates the default item height.

   Object An ADO, DAO recordset being loaded.  

Use the DataSource property to bind the control to an ADO recordset. Use PutItems property to fill the control from an array. When the user has changed the DataSource property, the control clears the old columns and items, and fetches the recordset columns and items. While control adding columns, the control fires AddColumn event While control loads the items from a recordset the control fires the InsertItem event. Use the CellCaption property to retrieves the value of the cell. Use the PutItems to load an array to the control. Use the ConditionalFormats method to apply formats to a cell or range of cells, and have that formatting change depending on the value of the cell or the value of a formula.

The following VB sample binds an ADO recordset to the ExComboBox control:

Set rs = CreateObject("ADODB.Recordset")
rs.Open "Orders", "Provider=Microsoft.Jet.OLEDB.3.51;Data Source= D:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB", 3 ' Opens the table using static mode

Set ComboBox1.DataSource = rs

The DataSource clears the columns collection, and fill the record set into the combobox, like a list. Use SetParent method to make your list a hierarchy.

The following C++ sample binds a table to the control:

#include "Items.h"
#include "Columns.h"
#include "Column.h"

#pragma warning( disable : 4146 )
#import <msado15.dll> rename ( "EOF", "adoEOF" )
using namespace ADODB;

_RecordsetPtr spRecordset;
if ( SUCCEEDED( spRecordset.CreateInstance( "ADODB.Recordset") ) )
	// Builds the connection string.
	CString strTableName = "Employees", strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
	CString strPath = "D:\\Program Files\\Microsoft Visual Studio\\VB98\\NWIND.MDB";
	strConnection += strPath;
		// Loads the table
		if ( SUCCEEDED( spRecordset->Open(_variant_t( (LPCTSTR)strTableName ), _variant_t((LPCTSTR)strConnection), adOpenStatic, adLockPessimistic, NULL ) ) )
			m_combobox.SetColumnAutoResize( FALSE );
			m_combobox.SetDataSource( spRecordset );
	catch ( _com_error& e )
		AfxMessageBox( e.Description() );

The #import statement imports definitions for ADODB type library, that's used to fill the control

Send comments on this topic.
1999-2018 Exontrol.COM, Software. All rights reserved.