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("Submit ter") & 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(objDat aReader.It em("Submit ter"))
item.SubItems.Add(objDataR eader.Item ("Date"))
item.SubItems.Add(objDataR eader.Item ("Tracking Num"))
item.SubItems.Add(objDataR eader.Item ("Des"))
item.SubItems.Add(objDataR eader.Item ("Solution "))
End While
Catch ex As Exception
MsgBox("Error")
End Try
'objDataReader.Close()
oSQLConn.Close()
TextBox1.Text = TextBox1.Text & objDataReader.Item("Submit
TextBox1.Text = TextBox1.Text & objDataReader.Item("Date")
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(objDat
item.SubItems.Add(objDataR
item.SubItems.Add(objDataR
item.SubItems.Add(objDataR
item.SubItems.Add(objDataR
End While
Catch ex As Exception
MsgBox("Error")
End Try
'objDataReader.Close()
oSQLConn.Close()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.ListV iewGroup)' : Argument matching parameter 'group' narrows from 'Object' to 'System.Windows.Forms.List ViewGroup' .
'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.
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.ListV
'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
JPaulinos solution didn't seem to work either.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I GOT IT.....It was this line:
item = ListView1.Items.Add(objDat aReader.It em("Submit ter"))
I just had
ListView1.Items.Add(objDat aReader.It em("Submit ter"))
I knew it was something easy....Thanks guys..
item = ListView1.Items.Add(objDat
I just had
ListView1.Items.Add(objDat
I knew it was something easy....Thanks guys..
2) What is the View mode for the Listview?
Bob