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


Hi, I am using GridDataBoundGrid ver I am experiencing problems with selection: When i delete a row from underlying DataSource (which is DataTable), even though next row appears selected on screen, my SelectionChanged event handler does not receive any notification. My grid has following settings: myGrid.AllowDragSelectedCols = true; myGrid.AllowResizeToFit = false; myGrid.AllowSelection = GridSelectionFlags.Row; myGrid.Dock = DockStyle.Fill; myGrid.EnableAddNew = false; myGrid.EnableEdit = false; myGrid.ListBoxSelectionMode = System.Windows.Forms.SelectionMode.One; myGrid.Location = new System.Drawing.Point(0, 0); myGrid.Name = "myGrid"; myGrid.OptimizeInsertRemoveCells = true; myGrid.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.GrayWhenLostFocus; myGrid.Size = new System.Drawing.Size(224, 230); myGrid.SmartSizeBox = false; myGrid.SortBehavior = GridSortBehavior.SingleClick; myGrid.TabIndex = 0; myGrid.Text = "myGrid"; myGrid.ThemesEnabled = true; myGrid.UseListChangedEvent = true; Given below is the code that is used to delete a row: DataRow dr = myTable_.Rows.Find(deletedObj.Id); if (dr != null) { myTable_.Rows.Remove(dr); } I see a similar behaviour when a row is added ... what am i missing here ? thanks

4 Replies

AD Administrator Syncfusion Team June 20, 2005 09:00 AM UTC

You can use this event to catch rows being removed. this.gridDataBoundGrid1.Binder.RecordsRemoved

AD Administrator Syncfusion Team June 20, 2005 05:32 PM UTC

Right, but the actual problemm i am experiencing, is that when a row is removed and next row is slected, my event handler does not get SelectionChanged or SelectionChanging notification. thanks >You can use this event to catch rows being removed. > >this.gridDataBoundGrid1.Binder.RecordsRemoved >

AD Administrator Syncfusion Team June 22, 2005 03:43 AM UTC

After a DataRow is deleted from DataTable, do i have to explicitly referesh the grid ? I checked Selections.GetSelectedRanges right after a row is deleted, it is empty but next row is still shown selected on screen .. Should i just explicity select the next row ? I believe that next row should be selected automatically and my event handler should get called .. thanks

AD Administrator Syncfusion Team June 22, 2005 07:35 AM UTC

Try this. It worked for me to raise a SelectionChanged event when a row from the datatable was deleted. Add a handler to the ListChanged event on the DataView associated with the CurrencyManager for your grid. CurrencyManager cm = grid.BindingContext[grid.DataSource, grid.DataMember] as CurrencyManager; DataView dv = cm.List as DataView; dv.ListChanged += new ListChangedEventHandler(dv_ListChanged); Then in the handler, if a row is being deleted, and the current rowindex needs to be adjusted, adjust it.
private void cm_PositionChanged(object sender, EventArgs e)
	CurrencyManager cm = sender as CurrencyManager;
	int rowIndex = this.gridDataBoundGrid1.Binder.PositionToRowIndex(cm.Position);
	if(this.gridDataBoundGrid1.CurrentCell.RowIndex != rowIndex)
		this.gridDataBoundGrid1.CurrentCell.MoveTo(rowIndex, this.gridDataBoundGrid1.CurrentCell.ColIndex);
		GridSelectionChangedEventArgs ea = new GridSelectionChangedEventArgs(GridRangeInfo.Row(rowIndex), null, GridSelectionReason.SelectRange);

Live Chat Icon For mobile
Up arrow icon