How to write AddHandler for multiple ComboBoxes

  • Thread starter Thread starter MRM256
  • Start date Start date
M

MRM256

Guest
Hi Everyone:

My application looks at the construction of a database's table and dynamically creates a data entry form.

1396270.png

This form contains two foreign key columns: CountryID and StateID. I wish to modify the dynamically created forms so they will have a combo box for the foreign key columns.

1396271.png
However, in order to make the combo boxes functional I have to tell it which column is the ValueMember and which column is the DisplayMember. I have a routine that creates the combo boxes and labels for the required parent tables.

Private Function Create_TLPCboBoxes(ByVal tlpCtrl As TableLayoutPanel,
ByVal dtParentTbls As DataTable) _
As Control
Dim I As Long
Dim strName As String
Dim lblCtrl As New Label
Dim cboBox As New ComboBox
Dim schemaTbl As New DataTable
With tlpCtrl
.SuspendLayout()
.Controls.Clear()
.AutoSize = True
.AutoSizeMode = AutoSizeMode.GrowAndShrink
.BackColor = NewColor
.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single
.ColumnStyles.Add(New ColumnStyle(SizeType.AutoSize))
.Location = New Point(528, 10)
For I = 0 To dtParentTbls.Rows.Count - 1
strName = dtParentTbls.Rows(I).Item(0).ToString
schemaTbl = objOleDB.Get_OleDB_Tbl_Schema(cnnOleDB, strName)
lblCtrl = New Label
lblCtrl = Ins_Label_Ctrl(lblCtrl, "ValueMember-" & strName,
"ValueMember-" & strName)
'Add label control to Column 1
.Controls.Add(lblCtrl, 1, I)
cboBox = New ComboBox
cboBox = Ins_CboBox_Ctrl(cboBox, "VM_" & strName, schemaTbl)
'Add ComboBox to Column 2
.Controls.Add(cboBox, 2, I)
lblCtrl = New Label
lblCtrl = Ins_Label_Ctrl(lblCtrl, "DisplayMember-" & strName,
"DisplayMember-" & strName)
'Add label control to Column 1
.Controls.Add(lblCtrl, 3, I)
cboBox = New ComboBox
cboBox = Ins_CboBox_Ctrl(cboBox, "DM_" & strName, schemaTbl)
'Add ComboBox to Column 2
.Controls.Add(cboBox, 4, I)
Next I
.ResumeLayout()
End With
Return tlpCtrl
End Function
Private Function Ins_CboBox_Ctrl(ByVal ctrlCboBox As ComboBox,
ByVal strName As String,
ByVal dtaSource As DataTable) _
As Control

With ctrlCboBox
.Font = New Drawing.Font("Comic Sans MS",
10, FontStyle.Regular)

.Size = New Point(120, 100)
.DataSource = dtaSource
.DisplayMember = dtaSource.Columns(0).ToString
End With
Return ctrlCboBox
End Function
Private Function Ins_Label_Ctrl(ByVal ctrlLabel As Label,
ByVal strName As String,
ByVal lblText As String) _
As Control
With ctrlLabel
.AutoSize = True
.Font = New Drawing.Font("Comic Sans MS",
10, FontStyle.Regular)
.Name = strName
.Text = lblText
End With
Return ctrlLabel
End Function

These three routines add the necessary combo boxes to the main form. Here the user will select which column is the ValueMember for tblCountries. Which column is the DisplayMember for tblCountries and so forth for tblStates.

When the combo boxes are created the ValueMember is prefixed with "VM_".

cboBox = Ins_CboBox_Ctrl(cboBox, "VM_" & strName, schemaTbl). The DispalyMember is prefixed with "DM_". cboBox = Ins_CboBox_Ctrl(cboBox, "DM_" & strName, schemaTbl).

1396275.png

My problem is "How do I write an AddHandler routine to cover this?

Thanks,






MRM256

Continue reading...
 
Back
Top