Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why doesnt this IF statement ever run as true?

Status
Not open for further replies.

hexOffender

Programmer
Nov 6, 2006
146
US
Fr a VB2003 windows app, I want the forecolor to change if the Employee is not active.

If ds.Tables(0).Rows(introwindex)(4).ToString = "N" Then
With objListviewItem
.ForeColor = Color.Red
.Text = ds.Tables(0).Rows(introwindex).Item("Last Name")
.SubItems.Add(ds.Tables(0).Rows(introwindex).Item("First Name"))
.SubItems.Add(ds.Tables(0).Rows(introwindex).Item("Department"))
Dim s As String = "{" + (ds.Tables(0).Rows(introwindex)(3)).ToString + "}"
.SubItems.Add(s)
ListView1.Items.Add(objListviewItem)
objListviewItem.ForeColor = Color.Red

End With
Else
objListviewItem.Text = ds.Tables(0).Rows(introwindex).Item("Last Name")
objListviewItem.SubItems.Add(ds.Tables(0).Rows(introwindex).Item("First Name"))
objListviewItem.SubItems.Add(ds.Tables(0).Rows(introwindex).Item("Department"))
Dim s As String = "{" + (ds.Tables(0).Rows(introwindex)(3)).ToString + "}"
objListviewItem.SubItems.Add(s)
ListView1.Items.Add(objListviewItem)
End If

Next introwindex

When I step through the code, I can watch the value of the table in the dataset ( from (introwindex)(column 4)) and see that ist is in fact "N" as it should be, but the If statement will not execute the True path code and jumps to the else path.
 
try this

if ds.Tables(0).Rows(introwindex)(4).ToString.equals("N") Then

Christiaan Baes
Belgium

My Blog
 
Thanks Christiaan, but that still didn't work.
I can change all of the items forecolor, but I cant get the If statment to test true.
 
I would check

1. Column 4 is the right field. Or, just use the ColumnName.
2. The Column length is 1. If more than 1 then simply add the Trim method.
3. Add the .ToUpper method to ensure that "n" is converted to "N".

Just a thought.
 
It is easy to check the text in listview and change its properties to desired.

Here is an altered version of code I got from the internet. I have used it successfully.
Code:
   Public Sub MakeBoldNonReadItems(ByRef lvwView As ListView, ByRef colNbr As Integer)
       
        Dim Item As ListViewItem
        Dim myFont As System.Drawing.Font
        myFont = New System.Drawing.Font("Verdana", 9, FontStyle.Bold)
      
        With lvwView
            .BeginUpdate()
            For Each Item In .Items
                If Item.SubItems(colNbr).Text.ToString = "Y" Then
                    Item.Font = myFont
                Else
                End If
            Next
            .EndUpdate()
        End With

    End Sub

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Actually Mansii was correct.
The field in the table was 2 characters, but the data is only 1 char. Once I trimmed it down it worked fine.
 
The field in the table was 2 characters, but the data is only 1 char. Once I trimmed it down it worked fine.
In that case, the wrong data type has been specified in the database. Presumably, it has been set as char(2) and if you are not going to store 2 characters every time then it should have been char(1). If the data could be one or two characters, then it should have been set as varchar(2).


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top