Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
200
UltraGridRow.Rows.Contains() - How it works?
posted

I have two UltraGrids.

Both UltraGrid can pass rows from one grid to another using Drag & Drop. I need to check that the row doesn't already exist on the destination grid.

This is that I have done:

private void uGrid2_DragEnter(object sender, DragEventArgs e)
{
	if (e.Data.GetDataPresent(typeof(UltraGridRow)))
	{
		UltraGridRow row = e.Data.GetData(typeof(UltraGridRow)) as UltraGridRow;
		if (!uGrid2.Rows.Contains(row))
		{
			e.Effect = DragDropEffects.Copy;						
		}
	}            
}

1) Drag a row from the grid1 to GRID2
2) Repeat the same step, with the same row

The condition always returns false.

 

uGrid2.Rows.Contains(row)

always is false...

Why?

 

 

Parents
  • 467470
    Verified Answer
    Offline posted

    Hi,

    The Contains method doesn't look at the data in the row. It just looks at the actual instance of the object you pass in. So a row in the first grid will never exist in the second grid, because it will always be a different instance.

    So this will work if you try to drag a row from grid1 into grid1. But it will not work for dragging a row to a different grid.

    You will probably need to compare the data in the row, perhaps using some key value.

Reply Children
No Data