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:

With Me.DataGridView1

            For Each r As DataGridViewRow In .SelectedRows


                .Rows.RemoveAt(r.Index)
                DataGridView1.Update()

            Next

        End With

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 :)

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.

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

Thanks for your response

I have taken your idea into account but I would end up deleting the items from the database that way.

Isnt there a way of clearing the datagrid without deleting the items??

Looking forward to your replies


George

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:

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.

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

So what you want is to Simply Clear the Grid ?

If so if you are using a Dataset , you just have to say

Dataset.Clear();
DataTable.Clear();

Simple ne

Hey guys,

thanks for your responses but it doesnt seem to be solving my problem. Instead of the datagrid / textbox displaying the results of a new query it keeps retrieving the results from the previous query


:(

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.

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

I am developing an application right now and
having a hard time in clearing the
DataGrid contents.

I google the topic then
I found your answer.

Thanks, its a big help!

GOD BLESS!

I am developing an application right now and
having a hard time in clearing the
DataGrid contents.

I google the topic then
I found your answer.

Thanks, its a big help!

GOD BLESS!

let me see the code that you bind your Grid with

Thankyou for very helpful code.

Welcome vijay2040.

I'm glad you got it helpful. Please do not resurrect old threads. If you have any questions please ask. .... You are welcome to start your own threads.

Thread Closed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.