[RESOLVED][02/03] How to filter data on the listview
Hello everyone.. It's me again.. Could anyone help me upon filtering my listview?
My listview goes like this
Code:
This is my listview display
Source ItemCode Date Qty Description
123 ABC 1/11/05 1 TV
123 DEF 1/11/05 1 VCD
123 GHI 1/11/05 1 TVRACK
234 KLM 1/12/06 1 MIC
I want my data on listview to become like this
Source ItemCode Date Qty Description
123 ABC 1/11/05 1 Various Item
234 KLM 1/12/06 1 MIC
What happen to my display is that everytime the data exist already or it display multiple Source I want to to merge and on my description i want to display Various Item or Multiple item...Could anyone help me like this?
Last edited by shyguyjeff; Jan 14th, 2008 at 12:38 AM.
Last time i decided to do this on my query but i could not use group on it because i made a cross joins on my query so i decided to filter out my data on my application part... How can I group it?
Nice paul but how can I group that display? What I mean is that for those who have the same source i want to display one row only....Like for example since the they have the same source my itemcode will display only the first and on the description i want to display various item...i want them to merge at one row since they have the same source..How can I do that?
Code:
Instead of this...
Source ItemCode Date Qty Description
123 ABC 1/11/05 1 TV
123 DEF 1/11/05 1 VCD
123 GHI 1/11/05 1 TVRACK
It will become like this:
Source ItemCode Date Qty Description
123 ABC 1/11/05 1 Various Item
also, the itemcodes are all different. do you just want to use the first one?
what if the dates are different?
do you want the qty to be 1 various item or 3 various item?
Dim mySelectedDatabase = "EMCOR" + txtStore.Text
mySQLConnection = New SqlConnection("server=" & myServerName & ";trusted_connection=true;" & _
"database=" & mySelectedDatabase & "")
' create a command that would query to database
Dim cm As New SqlCommand("SELECT DISTINCT cust_id, storeid, department, date, a.source, i.itemcode, Qty, salesman, status = 'C', itemname, serialno, saletype = 'CS' FROM cashsale as cs INNER JOIN sale_aux as a ON cs.source = a.source LEFT OUTER JOIN sale_sn as n ON cs.source = n.source LEFT OUTER JOIN item as i ON a.itemcode = i.itemcode WHERE cs.cust_id = '" & txtCustID.Text & _
"' UNION SELECT DISTINCT cust_id, storeid, department, date, a.source, i.itemcode, Qty, salesman, status, itemname, serialno, saletype FROM sale as s INNER JOIN sale_aux as a ON s.source = a.source LEFT OUTER JOIN sale_sn as n ON s.source = n.source LEFT OUTER JOIN item as i ON a.itemcode = i.itemcode WHERE s.cust_id = '" & txtCustID.Text & "'", mySQLConnection)
mySQLConnection.Open()
Dim t As New DataTable
' initializing its column to complement on how many fields I want to return in my query command
t.Columns.Add("source")
t.Columns.Add("itemcode")
t.Columns.Add("date")
t.Columns.Add("department")
t.Columns.Add("Qty")
t.Columns.Add("itemname")
t.Columns.Add("saletype")
t.Columns.Add("serialno")
t.Columns.Add("salesman")
' a method to access read-only the result set.
Dim reader As SqlDataReader = cm.ExecuteReader()
While reader.Read()
' create new row
Dim r As DataRow = t.NewRow()
r(0) = reader("source")
r(1) = reader("itemcode")
r(2) = reader("date")
r(3) = reader("department")
r(4) = reader("Qty")
r(5) = reader("itemname")
r(6) = reader("saletype")
r(7) = reader("serialno")
r(8) = reader("salesman")
' add a row to a datatable
t.Rows.Add(r)
End While
' close reader
reader.Close()
' close the connection
mySQLConnection.Close()
For i As Integer = 0 To t.Rows.Count - 1
Dim li As ListViewItem = ListView1.Items.Add(t.Rows(i)("source").ToString())
li.SubItems.Add(t.Rows(i)("itemcode").ToString())
li.SubItems.Add(t.Rows(i)("date").ToString())
li.SubItems.Add(t.Rows(i)("department").ToString())
li.SubItems.Add(t.Rows(i)("Qty").ToString())
li.SubItems.Add(t.Rows(i)("itemname").ToString())
li.SubItems.Add(t.Rows(i)("saletype").ToString())
li.SubItems.Add(t.Rows(i)("serialno").ToString())
li.SubItems.Add(t.Rows(i)("salesman").ToString())
Next
Try
If (ListView1.Items.Count > 0) Then
ListView1.Items(0).Selected = True
Else
f.Visible = True
MessageBox.Show("No transaction found!")
Me.Visible = False
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
you could narrow down or filter your listview items most easily by improving your select statement. this isn't the best forum for database questions. try asking in the database development forum
a million thanks again to you paul....Thank you very much...i will try that also to post my query so that they Some of the member here can advice on my query...Thank you so much paul..
but w8 a minute paul..why is it that on my program it run but my problem is that it displays. "Specified argument was out of range of valid values. Parameter name: '-1' is not a valid value for 'displayIndex'