Hi,
I have problem in my coding, please help me.
I'm using DataSet (ObjDs) and DataTable (ObjDt).
My program use ListView, which only able to contain 10 records.
We must press BtnNext, if we want to see the next 10 records, etc.
I put ContextMenuStrip on that ListView.
If we press right click on 1 of the row and select "Edit", we can edit that selected row.
Then I update the new record into the Database.
Then I update the selected row to the newest record.
But if I press BtnNext then press btnPrevious, the ListView will show records before updated.
I realize that I need to update the record inside ObjDt, but the problem is..
I don't know how.
Can somebody have the solution for my problem?
Does it has something to do with "BindingContext" ?
Can anybody give me a coding example ? or please tell me what to do and learn, or give me some website to go.
Thank you very much.
nb. Forgive my bad english.
Here's some coding of mine.
I have problem in my coding, please help me.
I'm using DataSet (ObjDs) and DataTable (ObjDt).
My program use ListView, which only able to contain 10 records.
We must press BtnNext, if we want to see the next 10 records, etc.
I put ContextMenuStrip on that ListView.
If we press right click on 1 of the row and select "Edit", we can edit that selected row.
Then I update the new record into the Database.
Then I update the selected row to the newest record.
But if I press BtnNext then press btnPrevious, the ListView will show records before updated.
I realize that I need to update the record inside ObjDt, but the problem is..
I don't know how.
Can somebody have the solution for my problem?
Does it has something to do with "BindingContext" ?
Can anybody give me a coding example ? or please tell me what to do and learn, or give me some website to go.
Thank you very much.
nb. Forgive my bad english.
Here's some coding of mine.
VB.NET:
#Region "Deklarasi"
Dim ObjCmd As MySqlCommand
Dim ObjDa As MySqlDataAdapter
Dim ObjDs As New DataSet
Dim ObjDt As New DataTable
Dim Page As Integer
Dim PageCount As Integer
Dim RowFirst As Integer
Dim RowLast As Integer
Dim RowCount As Integer
Dim IndexFirst As Integer
Dim IndexLast As Integer
Dim LastRow As Integer
#End Region
Dim TTSearch, TSearch As String
#End Region
Private Sub txtNmBrg_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TxtNmBrg.KeyUp
If e.KeyCode = Keys.Enter And TxtNmBrg.Text.Length <> 0 Then
TTSearch = "A.NmBrg"
TSearch = TxtNmBrg.Text
Call SetObjDt_Search()
Call IsiLsvSearch()
End If
End Sub
Private Sub SetObjDt_Search()
Query = "SELECT A.KdBrg, A.NmBrg, B.Kemasan, B.HNA, " & _
"B.KdPbk, C.NmPbk, B.Supplier, A.Sisa, " & _
"A.SatuanT, B.HNAPPN, A.AmbilUntung, A.HJ, " & _
"A.ExpiredDate " & _
"FROM MBarang A, DBarang B, MPabrik C " & _
"WHERE A.KdBrg = B.KdBrg " & _
"AND C.KdPbk = B.KdPbk " & _
"AND " & TTSearch & " LIKE '%" & TSearch & "%' " & _
"ORDER BY A.NmBrg, B.Kemasan, C.NmPbk, B.Supplier"
Call SetObjDt(Query)
Call SetStatusPage1()
Call SetStatusPage2()
Call IsiTxtStatusPage()
Call IsiLblSearch()
End Sub
Private Sub SetStatusPage1()
Dim PageCountTemp As Decimal
Dim Sisa As Decimal
RowCount = ObjDt.Rows.Count
PageCountTemp = RowCount / 10
Sisa = (RowCount / 10) Mod 1
If Sisa <> 0 Then PageCountTemp = PageCountTemp + (1 - Sisa)
PageCount = CInt(PageCountTemp)
LastRow = RowCount - 1
Page = 1
End Sub
Private Sub SetStatusPage2()
RowFirst = ((Page - 1) * 10) + 1
RowLast = RowFirst + 9
If RowLast > RowCount Then RowLast = RowCount
IndexFirst = RowFirst - 1
IndexLast = RowLast - 1
End Sub
Private Sub IsiLsvSearch()
If ObjDt.Rows.Count = 0 Then Exit Sub
LsvSearch.Items.Clear()
Dim RR, CC As Integer
RR = 0
With LsvSearch
For R As Integer = IndexFirst To IndexLast
.Items.Add(ObjDt.Rows(R).Item(0))
CC = 1
For C As Integer = 1 To ObjDt.Columns.Count - 1
.Items(RR).SubItems.Add(ObjDt.Rows(R).Item(C))
If .Columns(CC).Text = "Pbk" Then
.Items(RR).SubItems(CC).Text &= " - " & ObjDt.Rows(R).Item(C + 1)
C += 1
End If
CC += 1
Next C
RR += 1
Next R
End With
End Sub
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
If Page = 1 Then Exit Sub
Page = 1
Call SetStatusPage2()
Call IsiTxtStatusPage()
Call IsiLsvSearch()
End Sub
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
If Page = 1 Then Exit Sub
Page -= 1
Call SetStatusPage2()
Call IsiTxtStatusPage()
Call IsiLsvSearch()
End Sub
'ContextMenuStrip for Edit
Private Sub CmiSearchEditNmBrg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmiSearchEditNmBrg.Click
Dim frEdit As New fEdit
Call IsiTxt_fEdit(frEdit)
frEdit.RbNmBrg.Checked = True
If frEdit.ShowDialog = Windows.Forms.DialogResult.OK Then
Call SetObjDt_Search()
Call IsiLsvSearch()
End If
TxtNmBrg.Focus()
End Sub