vendredi 1 octobre 2021

How can I get the checkbox.checked event to fire when I pass it as a parameter in vb.net?

I have programmed a long time but I’m relatively new to vb.net. And I’ve avoided subroutines and functions in which I passed parameters because I always get stuck. I’m trying to write a subroutine to pass information that will fill a TextBox or a checkbox with either the value from a table or clear the field or set to false. The first code below is an example of what I’ve been doing and this works. I trying to write a subroutine to pass 1.the name of the textbox or checkbox control on my form,2.the data row value, and 3.the column name in the table. The problem is when I passed a checkbox I can’t get the checked event to show on my control(CoreCol) that I passed. It knows it’s a checkbox and it will set the text of the checkbox too true or false but it won’t change the box checked.

This is an example of the old way that works. For a TextBox and a checkbox

' A Machine
If Not IsDBNull(r("A Machine")) Or Not IsNothing(r("A Machine")) Then
    TbXMachA.Text = r("A Machine")
Else
    TbXMachA.Text = ""
End If
If Not IsDBNull(r("A CO2 Box?")) Or Not IsNothing(r("A CO2 Box?")) Then
    CkbxCO2BoxA.Checked = r("A CO2 Box?")
Else
    CkbxCO2BoxA.Checked = False
End If

This works

LoadData2TextBox(Me. TbXMachA, r, "A Machine ")

This doesn’t

LoadData2TextBox(Me.CkbxCO2BoxA, r, "A CO2 Box?")

this is the sub routine I'm writing

Private Sub LoadData2TextBox(ByRef CoreCol As Control, CoreRow As DataRow, BoxStage As String)                
    If Not IsDBNull(CoreRow(BoxStage)) Then
        If TypeOf CoreCol Is TextBox Then
            CoreCol.Text = CoreRow(BoxStage)
        End If 
        If TypeOf CoreCol Is CheckBox Then
            CoreCol.??? = CoreRow(BoxStage)
        End If
    Else
        CoreCol.Text = ""
    End If



Aucun commentaire:

Enregistrer un commentaire