Solved

Binding to a label in windows form

Posted on 2006-06-22
6
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …
Simple Linear Regression

691 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