Solved

Binding to a label in windows form

Posted on 2006-06-22
6
242 Views
Last Modified: 2010-04-17
Below is my code for a function that fills a dataset and then calling the function to display the text.

However nothing displays.  I've used the propert explorer to set the text properties of the label..but that might be my problem.

Public Sub GetPathway(ByVal vABR_ID$)
          SqlDataAdapter_Pathway.SelectCommand.Parameters("@ABRID").Value = vABR_ID$
        SqlDataAdapter_Pathway.Fill(DsPathway1)
 
  End sub
 
  Private Sub GetPathway()
        Dim Pathway As String
        Dim IMG As Boolean
        If IMG = "1" Then
            lblPathway.Text = "IMG" & "DsPathway1.Pathway.text"
        Else
            lblPathway.Text = "DsPathway1.Pathway.text"
        End If
    End Sub

Thanks in advance.

0
Comment
Question by:TimSweet220
  • 3
  • 2
6 Comments
 
LVL 20

Expert Comment

by:alainbryden
ID: 16961789
Make sure that the properties "Word Wrap"= False and "Autosize"=True, otherwise your label may be putting your text right off the visible area.

Also, if you want the text to = DsPathway1.Pathway.text, then you need to get rid of the quotation marks, otherwise you won't see the data you are trying to look at, you will only exactly what's contained in the quotation marks.
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 16966485
what is DsPathway1.Pathway.text?? any way?/
0
 

Author Comment

by:TimSweet220
ID: 16970415
The .text should be there.

DsPathway1 is the dataset that pulls over two field  IMG and Pathway (database fields)

so my attempt was to se the lblPathway to the text of the field Pathway in the dataset  Pathway1.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 20

Expert Comment

by:alainbryden
ID: 16970531
Is the problem still occuring after making the adjustments I mentioned? I'm positive that those quotation marks shouldn't be surrounding the Pathway references.
0
 

Author Comment

by:TimSweet220
ID: 16970846
HEre is my code now.

Still not displaying but I'm not sure of the problem..  

Public Sub GetPathway(ByVal vABRID$)
        Dim Pathway As String
        Dim IMG As Boolean
        SqlDataAdapter_pathway.SelectCommand.Parameters("@ABR_ID").Value = vABRID$
        SqlDataAdapter_pathway.Fill(DsPathway1)

        If IMG = True Then
            lblPathway.Visible = True
            lblPathway.Text = "IMG" & Pathway
        ElseIf IMG = False Then
            lblPathway.Visible = True
            lblPathway.Text = Pathway
        Else
            lblPathway.Visible = False

        End If
    End Sub
0
 
LVL 20

Accepted Solution

by:
alainbryden earned 500 total points
ID: 16971335
Try this before anything:

lblPathway.Visible = true
lblPathway.Text = "Before"

See if that displays. If nothing is displaying, then I'm guesing the reason is that IMG is always false, and that the String 'Pathway' which you never seem to have set anywhere in there, is an empty string, so there is nothing to display.

also note that your ELSE statement will never be run, because IMG is always either true or false, so you can remove it entirely.

If the original
lblPathway.Visible = true
lblPathway.Text = "Before"
doesn't cause anything to be displayed, then you need to do a few things:
1. Make sure the properties I mentioned before are set appropriately
2. Make sure that nothing immediately following this method sets the lblPathway label visibility to false, or clears it before you get the chance to see it.
3. Make sure you are referencing the correct label, that it is placed visibly, and that it is wide enough to display the text.

If all of that fails then we have to look at how your method is called and what data members you have.

Another little hint is that often, when things aren't working for one reason or another, you can force the program to smarten up by adding the line:
DoEvents
to your code. It just seems to work in some weird situations. Especially when it comes to updating a form display.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
"best practice" architecture for adding mobile devices to an existing Webforms MS-SQL project 8 135
bigHeights  challenge 13 59
countPairs challenge 7 65
strDist challenge 35 96
A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now