Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27201

Filtered Binding Source. How to Update/Delete my DataTable?

$
0
0
Good Day! Please help me on this :).
Im creating Windows Form Application. I collecting user inputs from different forms and save it to a DataTable.

Code:

Dim temptable as new Datatable
temptable.Columns.Add("Name")
temptable.Columns.Add("ID")
temptable.Columns.Add("Department")

Code:

temptable.Rows.add("Jack",1,"Sales")
temptable.Rows.add("John",2,"Sales")
temptable.Rows.add("Mary",3,"IT")
temptable.Rows.add("Joseph",4,"IT")

Then i bind the Datatable to a BindingSource add do some Filtering:
Code:

Dim bs as New BindingSource
bs.Datasource = temptablebs.Filter = "Department LIKE '%" & Sales  & "%' "


Then i use the bindingsource as my datasource for my Datagridview:
Code:

DataGridView1.DataSource = bs
Now i need to update and delete a row on my datatable which is filtered in my Datagridview.
I also added buttons in the Datagrid for deleting and updating.
Code:


Dim colConf As New DataGridViewButtonColumn       
colConf.HeaderText = "Account"       
colConf.Text = "Edit"   
colConf.Name = "colconf"       
colConf.UseColumnTextForButtonValue = True       
Me.DataGridView1.Columns.Add(colConf)


Code:

        'Datagridview Delete BUTTON       
Dim colConf2 As New DataGridViewButtonColumn       
colConf2.HeaderText = "Account"       
colConf2.Text = "Delete"       
colConf2.Name = "colconf"       
colConf2.UseColumnTextForButtonValue = True       
Me.DataGridView1.Columns.Add(colConf2)

For Deleting a Row, i used:

Code:

bs.RemoveCurrent
When Delete Button is Pressed.

Now, is there a way to make my EDIT button work? I want the selected row to be in textboxes of another form.
And Save the Changes to my Datatable
Code:

(temptable)
Please Guide Me. Thanks and God Bless.

Viewing all articles
Browse latest Browse all 27201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>