Link to home
Start Free TrialLog in
Avatar of clebo99
clebo99

asked on

Easy ListView Question

For some reason, my ListView is only adding the first column and not the other columns.   I know my logic/query is workingb because I did a test where I had a TEXTBOX and just added the information to the Textbox from the query using:

TextBox1.Text = TextBox1.Text & objDataReader.Item("Submitter") & vbCrLf
TextBox1.Text = TextBox1.Text & objDataReader.Item("Date") & vbCrLf

I'm sure it's something easy that I'm forgetting.......I just cannot seem to find it.  I'm pretty sure it's something with the variable ITEM.

My Current Code:

Dim oSQLConn As SqlClient.SqlConnection = New SqlClient.SqlConnection()
        Dim str As String
        Dim str2 As SqlClient.SqlCommand = New SqlClient.SqlCommand
        Dim item As ListViewItem
        Dim objDataReader As SqlClient.SqlDataReader
        oSQLConn.ConnectionString = "Data Source=fakecpuname; Initial Catalog=fakedbname; Integrated Security=SSPI"
        str = "Select * from main"

        Try
            oSQLConn.Open()
            str2.CommandText = str
            str2.Connection = oSQLConn
            item = New ListViewItem
            objDataReader = str2.ExecuteReader()
            While objDataReader.Read
                ListView1.Items.Add(objDataReader.Item("Submitter"))
                item.SubItems.Add(objDataReader.Item("Date"))
                item.SubItems.Add(objDataReader.Item("TrackingNum"))
                item.SubItems.Add(objDataReader.Item("Des"))
                item.SubItems.Add(objDataReader.Item("Solution"))
            End While
        Catch ex As Exception
            MsgBox("Error")
        End Try
        'objDataReader.Close()
        oSQLConn.Close()
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
1) Do you have multiple column headers defined?

2) What is the View mode for the Listview?

Bob
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clebo99
clebo99

ASKER

The View Mode is DETAILS......and I can see the first column information but the remaining column information is just blank.

Manowitz.  I tried your solution but I keep getting an error:

Error      1      Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
    'Public Sub New(group As System.Windows.Forms.ListViewGroup)': Argument matching parameter 'group' narrows from 'Object' to 'System.Windows.Forms.ListViewGroup'.
    'Public Sub New(items() As String)': Argument matching parameter 'items' narrows from 'Object' to '1-dimensional array of String'.
    'Public Sub New(text As String)': Argument matching parameter 'text' narrows from 'Object' to 'String'.      C:\Documents and Settings\pptadmritschcw\My Documents\Visual Studio 2005\Projects\First Application\First Application\Form1.vb      26      25      First Application
 
JPaulinos solution didn't seem to work either.  
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clebo99

ASKER

I GOT IT.....It was this line:


                item = ListView1.Items.Add(objDataReader.Item("Submitter"))

I just had


                ListView1.Items.Add(objDataReader.Item("Submitter"))

I knew it was something easy....Thanks guys..