| | |
Clearing The Contents Of A Datagridview
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 21
Reputation:
Solved Threads: 0
Hey guys
As many of you are well aware I creating an EPOS System
I have a datagrid that stores details about all of the items which the user wishes to buy in the transaction.
However if the user changes his mind I have a feature that cancels the row in the datagrid.
This is my code for this feature:
The code functions fine, however a problem arises if I enter a new row into the datagridview, the previous row I recently cancelled appears again.
Does anyone know how I solve this problem??
All ideas welcome
As many of you are well aware I creating an EPOS System
I have a datagrid that stores details about all of the items which the user wishes to buy in the transaction.
However if the user changes his mind I have a feature that cancels the row in the datagrid.
This is my code for this feature:
With Me.DataGridView1
For Each r As DataGridViewRow In .SelectedRows
.Rows.RemoveAt(r.Index)
DataGridView1.Update()
Next
End WithThe code functions fine, however a problem arises if I enter a new row into the datagridview, the previous row I recently cancelled appears again.
Does anyone know how I solve this problem??
All ideas welcome
•
•
Join Date: May 2007
Posts: 45
Reputation:
Solved Threads: 1
You have to remove the item from the database that the datagrid is getting the information from, instead of just the actual datagrid. Heres a example.
VB Syntax (Toggle Plain Text)
If Grid2.SelectedCells.Count <> 0 Then Table2TableAdapter.Connection.Open() Dim I As Integer = Grid2.CurrentCell.RowIndex TestdbDataSet.Table2.Rows.Item(I).Delete() TestdbDataSet.GetChanges() Table2TableAdapter.Update(TestdbDataSet.Table2) Table2TableAdapter.Connection.Close() Else MsgBox("There are no items selected.") End If
•
•
Join Date: May 2007
Posts: 45
Reputation:
Solved Threads: 1
Well. Im still kinda new to VB .NET, but Datagrids are basically only representative of a dataset, they dont actually store the data. So in effect, the datagrid only shows what the actual dataset contains. One way you can get around deleting the data from the actual dataset is to create a copy of the dataset, and actually delete data from that set. Heres an example:
And then you can delete data from the tempTable datatable instead of your actual database.
VB Syntax (Toggle Plain Text)
Dim tempTable As New testdbDataSet.Table1 Table1TableAdapter.Fill(tempTable) DataGrid.DataSource = tempTable
And then you can delete data from the tempTable datatable instead of your actual database.
Last edited by cellus205; Oct 24th, 2008 at 1:37 pm.
•
•
Join Date: Nov 2007
Posts: 21
Reputation:
Solved Threads: 0
Hey guys
thankyou for your responses,
I did leave this problem and continued to develop the rest of the system however it appears it is affecting the rest of system. Whenever I empty textboxes and attempt to populate them again the previous result appears in the textbox instead of the new one.
I do believe that Cellus response is correct but what troubles me now is that how to empty the dataset?
I have searched thoroughly on the internet and cant find an answer
Any ideas??
Your responses are much appreciated
George
thankyou for your responses,
I did leave this problem and continued to develop the rest of the system however it appears it is affecting the rest of system. Whenever I empty textboxes and attempt to populate them again the previous result appears in the textbox instead of the new one.
I do believe that Cellus response is correct but what troubles me now is that how to empty the dataset?
I have searched thoroughly on the internet and cant find an answer
Any ideas??
Your responses are much appreciated
George
So what you want is to Simply Clear the Grid ?
If so if you are using a Dataset , you just have to say
Simple ne
If so if you are using a Dataset , you just have to say
VB.NET Syntax (Toggle Plain Text)
Dataset.Clear();
VB.NET Syntax (Toggle Plain Text)
DataTable.Clear();
Simple ne
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
•
•
Join Date: Nov 2007
Posts: 21
Reputation:
Solved Threads: 0
Hey guys, I have found the root to the problem.
Below is a snippet of code I used in order to retrieve several query results items into the datagrid.
The above snippet of code stores my queries into string.
What we were doing previously to clear the data of the datagrid was correct, however the above snippet of code which would store my query result as a string, would then load up the same string again whenever I would click the search buttion.
By removing this snippet of code, it would solve the problem, however, I wouldnt be able to hold more than one query result in the datagrid at a time then.
Does anybody know how I could solve this, or tackle it??
Any feedback is appreciated
George
Below is a snippet of code I used in order to retrieve several query results items into the datagrid.
VB.NET Syntax (Toggle Plain Text)
If strSearch = "" Then strSearch = txtItemId.Text Else strSearch = strSearch & " ' or [item_ID] = ' " & txtSearch.Text txtSearch.Clear() End If
The above snippet of code stores my queries into string.
What we were doing previously to clear the data of the datagrid was correct, however the above snippet of code which would store my query result as a string, would then load up the same string again whenever I would click the search buttion.
By removing this snippet of code, it would solve the problem, however, I wouldnt be able to hold more than one query result in the datagrid at a time then.
Does anybody know how I could solve this, or tackle it??
Any feedback is appreciated
George
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: problem for printing
- Next Thread: Vb .net project work
| Thread Tools | Search this Thread |
"crystal .net .net2005 2008 access add advanced application array assignment basic beginner box button buttons center click client code combo convert cpu data database datagrid datagridview designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall forms html image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity pan picturebox picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vba vbnet vista visual visualbasic visualbasic.net visualstudio.net web winsock wpf wrapingcode xml





