Click here to Skip to main content
15,891,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have user control that accept 3 String and set it into 3 labels.
on load of the user control i set default value,and when i pass the paremeter the label will change it's text.
but my problem is the lables not changing it's value at all, i check the code and see the user control read all the value but nothing happen :(

Sorry for my bad english

-----------
Form Login
------------
Imports System.Data.OleDb
Imports System.IO
Imports System
Imports System.Windows.Forms

Public Class FrmLogin
VB
Dim mb As New _userCompanyBar()
   



    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub







    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        Me.Controls.Add(mb)
        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub _BtnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _BtnLogin.Click

    End Sub

    Private Sub _BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _BtnCancel.Click
        Me.Close()
    End Sub

    Private Sub LoginForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim _companyBUS As CompanyBUS
        _companyBUS = New CompanyBUS
        Dim _CompanyVO = New CompanyVO()
        _CompanyVO = _companyBUS.getCompany()
        Try

            If Not (_CompanyVO Is Nothing) Then
                '  Dim CompanyBar As New _userCompanyBar
                mb.setData(_CompanyVO.CompanyName, _CompanyVO.CompanyAddress, _CompanyVO.CompanyPhone)




            End If
        Catch ex As Exception
        End Try
    End Sub
End Class



---------------
_userCompanyBar
-------------
VB
>_userCompanyBar


Imports System.ComponentModel

Public Class _userCompanyBar
    Dim Company = "Company Name"
    Dim CompanyAddress = "Company Address"
    Dim CompanyPhone = "Company Phone"



    Public Sub CompanyBar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        _lbCompanyName.Text = Company
        _lbCompanyAddress.Text = CompanyAddress
        _lbCompanyTelp.Text = CompanyPhone

    End Sub

    Private Sub _pnBackgroundColor_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles _pnBackgroundColor.Paint

    End Sub

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Public Sub New(ByVal _CompanyName As String, ByVal _CompanyAdresse As String, ByVal _CompanyPhone As String)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        setData(_CompanyName, _CompanyAdresse, _CompanyPhone)


    End Sub
    Public Sub setData(ByVal _CompanyName As String, ByVal _CompanyAdresse As String, ByVal _CompanyPhone As String)

        _lbCompanyName.Text = _CompanyName
        _lbCompanyAddress.Text = _CompanyAdresse
        _lbCompanyTelp.Text = _CompanyPhone
    End Sub

    Private Sub _lbCompanyTelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _lbCompanyTelp.Click

    End Sub
End Class</pre>
Posted
Updated 17-Aug-13 3:09am
v4

1 solution

Probably, you aren't referencing the instance of your user control that you are displaying. Unless you do, you can make all the changes you like, it won't affect the display one iota!

Check the code where you call the setDate Method - and make sure you are calling it on the correct instance, rather than a new one.
 
Share this answer
 
Comments
Ahmad Al Halabi 17-Aug-13 8:22am    
i Call "setData" in the user control

Sub setData(ByVal Name As String, ByVal Address As String, ByVal Phone As String)

_lbCompanyName.Text = Name
_lbCompanyAddress.Text = Address
_lbCompanyTelp.Text = Phone
End Sub
OriginalGriff 17-Aug-13 9:50am    
No - that's the *definition* of setData, which you have already shown.
Where do you use it?
As in:
myUserControlInstance.setData("Joe Smith", "At home", "0041999");
Ahmad Al Halabi 17-Aug-13 9:54am    
i write it in the Main Form

If Not (_CompanyVO Is Nothing) Then
mb.setData(_CompanyVO.CompanyName, _CompanyVO.CompanyAddress, _CompanyVO.CompanyPhone)
end if
OriginalGriff 17-Aug-13 10:03am    
So what is in mb?
Ahmad Al Halabi 17-Aug-13 10:04am    
Dim mb As New _userCompanyBar()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900