We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Databound Grid will not remove records when row filter changes.

I have been struggling with this one far too long. It is very simple. A data bound grid bound to a data view containing 4 columns. The 4th column is a Boolean and is used to filter the dataview. If the 4th column is set to false the row should be removed from the grid. This is not happening. The user can set the value of the 4th column indirectly by clicking a button. I have tried two ways of setting the value of the 4th column. 1) Directly on the dataview. When I do this the grid will not remove the row until I click on a different row. _dvCompanies(_grdCompanyList.Binder.RowIndexToPosition(_grdCompanyList.CurrentCell.RowIndex))("Active") = False _grdCompanyList.Binder.EndEdit() _grdCompanyList.Refresh() 2) Through the binder. When I do this the grid will clear out the row, but not remove it. If I remove a second row the first remove is removed, but the second is blanked out. _grdCompanyList(_grdCompanyList.CurrentCell.RowIndex, _ _grdCompanyList.Binder.FieldToColIndex( _ _grdCompanyList.Binder.NameToField(“Active”))).CellValue = False If I sort the grid after any one of these two actions, the grid corrects itself. Please see full source below. Any help would be greatly appreciated. Thank you, Per Imports Syncfusion.Windows.Forms.Grid Public Class CompanyListing Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() ''This call is required by the Windows Form Designer. InitializeComponent() ''Add any initialization after the InitializeComponent() call End Sub ''Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub ''Required by the Windows Form Designer Private components As System.ComponentModel.IContainer ''NOTE: The following procedure is required by the Windows Form Designer ''It can be modified using the Windows Form Designer. ''Do not modify it using the code editor. Friend WithEvents _grdCompanyList As Syncfusion.Windows.Forms.Grid.GridDataBoundGrid Friend WithEvents Button1 As System.Windows.Forms.Button Private Sub InitializeComponent() Me._grdCompanyList = New Syncfusion.Windows.Forms.Grid.GridDataBoundGrid Me.Button1 = New System.Windows.Forms.Button CType(Me._grdCompanyList, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() '' ''_grdCompanyList '' Me._grdCompanyList.AllowDragSelectedCols = True Me._grdCompanyList.Location = New System.Drawing.Point(0, 0) Me._grdCompanyList.Name = "_grdCompanyList" Me._grdCompanyList.OptimizeInsertRemoveCells = True Me._grdCompanyList.ShowCurrentCellBorderBehavior = Syncfusion.Windows.Forms.Grid.GridShowCurrentCellBorder.GrayWhenLostFocus Me._grdCompanyList.Size = New System.Drawing.Size(336, 384) Me._grdCompanyList.SmartSizeBox = False Me._grdCompanyList.SortBehavior = Syncfusion.Windows.Forms.Grid.GridSortBehavior.DoubleClick Me._grdCompanyList.TabIndex = 0 Me._grdCompanyList.Text = "GridDataBoundGrid1" Me._grdCompanyList.UseListChangedEvent = True '' ''Button1 '' Me.Button1.Location = New System.Drawing.Point(392, 96) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 1 Me.Button1.Text = "Button1" '' ''CompanyListing '' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14) Me.ClientSize = New System.Drawing.Size(498, 384) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me._grdCompanyList) Me.Font = New System.Drawing.Font("Tahoma", 8.25!) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog Me.MaximizeBox = False Me.MinimizeBox = False Me.Name = "CompanyListing" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent Me.Text = "Companies" CType(Me._grdCompanyList, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region #Region "Private Members" Private _dvCompanies As DataView = Nothing #End Region #Region "Form Events" Private Sub CompanyListing_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load _initializeGrid() _bindGrid() _setupColumns() End Sub #End Region #Region "Add/Edit/Delete" Private Sub _DeleteCompany() If MessageBox.Show("Are you sure you want to delete the selected company?", "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = DialogResult.OK Then _grdCompanyList(_grdCompanyList.CurrentCell.RowIndex, _ _grdCompanyList.Binder.FieldToColIndex( _ _grdCompanyList.Binder.NameToField("Active"))).CellValue = False _grdCompanyList.Binder.EndEdit() _grdCompanyList.CurrentCell.Refresh() End If End Sub #End Region #Region "Grid Related" Private Sub _initializeGrid() End Sub Private Sub _bindGrid() _dvCompanies = CompanyController.GetCompanies().Tables(0).DefaultView _dvCompanies.Sort = "CompanyName" _dvCompanies.RowFilter = "Active = True" _grdCompanyList.DataSource = _dvCompanies End Sub Private Sub _setupColumns() End Sub #End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click _DeleteCompany() End Sub

5 Replies

AD Administrator Syncfusion Team September 20, 2005 06:06 PM UTC

The version I am using is: 3.201.1.515


AD Administrator Syncfusion Team September 22, 2005 12:27 PM UTC

Hi Per, Calling DataTable.AcceptChanges() fixes the issue. _dvCompanies[_grdCompanyList.Binder.RowIndexToPosition(_grdCompanyList.CurrentCell.RowIndex)]["Active"] = false; _grdCompanyList.Binder.EndEdit(); _dvCompanies.Table.AcceptChanges(); Best regards, Stanley


AD Administrator Syncfusion Team September 22, 2005 02:44 PM UTC

Hi Stanely, I can''t call AcceptChanges since it will reset the rowstate and I won''t be able to commit the changes later to the database. Do you have any other ideas? Thanks, Per >Hi Per, > >Calling DataTable.AcceptChanges() fixes the issue. > >_dvCompanies[_grdCompanyList.Binder.RowIndexToPosition(_grdCompanyList.CurrentCell.RowIndex)]["Active"] = false; >_grdCompanyList.Binder.EndEdit(); >_dvCompanies.Table.AcceptChanges(); > > >Best regards, >Stanley


AD Administrator Syncfusion Team September 22, 2005 10:35 PM UTC

Here is a little sample. http://www.syncfusion.com/Support/user/uploads/GDBG_Bool_7bfc3f2b.zip You can either check the checkbox to see the row removed (uses the grid.Binder.DirectCellSaveInfo setting.) Or, you can click the button and set the checkbox outside the grid on teh currentrow and see it removed.


AD Administrator Syncfusion Team September 23, 2005 12:51 PM UTC

Thanks Clay, that worked. >Here is a little sample. > >http://www.syncfusion.com/Support/user/uploads/GDBG_Bool_7bfc3f2b.zip > > >You can either check the checkbox to see the row removed (uses the grid.Binder.DirectCellSaveInfo setting.) Or, you can click the button and set the checkbox outside the grid on teh currentrow and see it removed.

Loader.
Live Chat Icon For mobile
Up arrow icon