I'm trying to dynamically add datacolumns to a datatable, then reflect those changes in a datagridview. This is what I have to add them:
This is what I'm using to remove them:Code:Private Sub BindingNavigatorAddNewItem_Click(sender As System.Object, e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click Dim i As Integer = DataSet1.Tables(0).Columns.Count + 1 Dim col As New DataColumn col.ColumnName = i.ToString 'Creates a blank row if there are no columns If i = 1 Then DataSet1.Tables(0).NewRow() End If 'Creates the new column DataSet1.Tables(0).Columns.Add(col) 'Refreshes the datagridview DataGridView1.Refresh() End Sub
When I click my add button, the countitem goes up and when I click my delete button the countitme goes down. My problem is that the changes aren't reflecting in the datagridview. The dataset is untyped. The bindingsource and the datagridview's datasource is dataset1 and the datamember is table1. Any suggestions?Code:Private Sub BindingNavigatorDeleteItem_Click(sender As System.Object, e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click 'Iterates through each selected column For Each col As DataGridViewColumn In DataGridView1.SelectedColumns 'Removes those columns DataSet1.Tables(0).Columns.Remove(col.Name) Next 'If there are no columns left then delete all the rows If DataSet1.Tables(0).Columns.Count = 0 Then For Each dr As DataRow In DataGridView1.Rows DataSet1.Tables(0).Rows.Remove(dr) Next End If 'Refreshes the datagridview DataGridView1.Refresh() End Sub




Reply With Quote