Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have listview which loads data from the SQL DB.For a boolean value in the DB i want to show a String value. Please let me know how to do this. Check the code to understand better. Please help

Public Sub PerformLoad()
        Try
            lvwMain_default.Items.Clear()
            Dim mitem As ListViewItem
            'Dim frmLgn As New frmLogin
            Dim DataSt As New DataSet
            
            Dim sqlSelIss As String = "select IssID, Descrptn,_status,priority,First_name,Last_Name from User_Details where Emp_ID = issDtl.created_by as Name,Created_On from Issue_Details as issDtl where project_id = '" proId.ToString  "'"
           DataSt = DataStore.GetDataset(sqlSelIss, sqlConnStr)

            For Each row As DataRow In DataSt.Tables(0).Rows
                mitem = New ListViewItem


                mitem.Text = row.Item("IssID") 
                mitem.SubItems.Add(row.Item("Descrptn"))
              
 
            ' status column return a boolean value,
            ' i want to show Active for True and Inactive
            ' for False
               
                mitem.SubItems.Add(row.Item("Status"))
                mitem.SubItems.Add(row.Item("priority"))
                mitem.SubItems.Add(row.Item("Name"))
                mitem.SubItems.Add(row.Item("Created_On"))

                lvwMain_default.Items.Add(mitem)
            Next


        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub
Posted

A quick way would be:


If row.Item("Status").toString = "True" then
mitem.subItems.Add("Active")
ElseIf row.Item("Status").toString = "False" then
mitem.subItems.Add("Inactive")
End If<pre>
 
Share this answer
 
v2
Comments
souvikd 29-Jul-10 5:49am    
Hey thanks for the code, it works fine... i m also trying to add a color to that particular value, i m doing the following but it doesnt work
 If row.Item("Status") = True Then
                    mitem.SubItems.Add("Active").ForeColor = Color.GreenYellow
                ElseIf row.Item("Status") = False Then
                    mitem.SubItems.Add("Inactive")
                End If
I think you have to set the listview UseItemStyleForSubItems property to false.
Check this[^]and this[^].


If my answer solves your problem please mark it as Accepted Answer.
 
Share this answer
 
v3

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