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.
Unfortunately, activation email could not send to your email. Please try again.


Thread ID:





30506 Jun 19,2005 06:35 PM Jun 22,2005 03:35 AM Windows Forms 4
Tags: GridControl
Administrator [Syncfusion]
Asked On June 19, 2005 06:35 PM

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

Administrator [Syncfusion]
Replied On June 20, 2005 05:00 AM

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

Administrator [Syncfusion]
Replied On June 20, 2005 01:32 PM

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 >

Administrator [Syncfusion]
Replied On June 21, 2005 11:43 PM

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

Administrator [Syncfusion]
Replied On June 22, 2005 03:35 AM

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


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.