Hi All,
I have a situation in code, where the UltraGrid is being used in Load on Demand mode (Virtual Mode) by using the Ultra Data Source where the underlying source is a Data Table.
Now the total rows returned by the source DB are near 2000. I have implemented a functionality where the user can jump to a cell down in grid by using a small tool "Go To" just as in Excel. I copied the content of the first cell in first column ( this columns contains date data) and then used the "Go To" tool to jumped to Column 0 and Row 1360 in Grid. I did so by using the following code:
<Code>
private void ActivateCell(int RowIndex, string ColName)
{
this.resultsGrid.ActiveRowScrollRegion.ScrollPosition = RowIndex; this.resultsGrid.ActiveRow = this.resultsGrid.Rows[RowIndex]; this.resultsGrid.ActiveCell = this.resultsGrid.Rows[RowIndex].Cells[ColName]; this.resultsGrid.Rows[RowIndex].Cells[ColName].Activate(); this.resultsGrid.Rows[RowIndex].Cells[ColName].Selected = this.resultsGrid.Rows[RowIndex].Cells[ColName].Activate();
}
</Code>
Now the real problem is that as I copied the contents of the first cell and now when I try to paste it in the zero(th) cell in 1360th row, it jumps back to the first cell. The paste command is being used by UltraGrid.PerformAction(UltraGridAction.Paste). I also stepped through the code here that which cell was the active on before PerformAction line o code and it was the 1360th Row and its zero cell.
Can anyone guide me where am I wrong or if there is some other way to handle this?
Due Regards,
Talha Muhammad
Hi,
Muhammad Talha said:So it does allow the AllowMultiCellOperations to Paste but only pastes the contents in the first selected cell? How can I over come this? Or does it not work for Virtual Mode?
I'm not sure about this. There's no reason why this should not work in virtual mode, so I don't think that has anything to do with the issue. Perhaps you have to select a range of cells that is the same size as the range you copied or cut from?
Muhammad Talha said:Can you explaing the second last line of code in above function; does Activate() function for an UltraGridCell returns a bool value, I tried it with a return bool variable (bool bResult = this.resultsGrid.Rows[RowIndex].Cells[ColName].Activate(); ) but bResult was always false, though the code works fine now...
I'm not surewhat Activate is supposed to return.Does it say in the documentation? The obvious thing would be for it to return success of failure.But perhaps it returns false if the cell is already active and you try to activate it again, since this would not actually do anything.
Mike thanks for the reply, it did help me solve the problem.
Yes, I was making a couple of mistakes in code, when I was jumping to the cell ([1360][0]) down in Grid, it was activated and was also being added in the selected cells collection in grid. As I stepped through the code, I figured out that it was pasting the copied content from clipboard to the first cell among the selected ones so I cleared the Selected Cells collection before activating the new cell, but there is one problem yet, the paste code that is written behind a Menu Item is as follow:
<code>
private bool OnPaste()
this.resultsGrid.DisplayLayout.Override.AllowMultiCellOperations = AllowMultiCellOperation.Paste; bool bResult = resultsGrid.PerformAction(UltraGridAction.Paste); return bResult;
bool bResult = resultsGrid.PerformAction(UltraGridAction.Paste);
return bResult;
</code>
So it does allow the AllowMultiCellOperations to Paste but only pastes the contents in the first selected cell? How can I over come this? Or does it not work for Virtual Mode?
and for last, the modified ActivateCell function is now:
this.resultsGrid.Selected.Cells.Clear(); this.resultsGrid.ActiveRowScrollRegion.ScrollPosition = RowIndex;this.resultsGrid.ActiveRow = this.resultsGrid.Rows[RowIndex]; this.resultsGrid.Rows[RowIndex].Cells[ColName].Activate(); this.resultsGrid.Rows[RowIndex].Cells[ColName].Selected = true;
this.resultsGrid.ActiveRowScrollRegion.ScrollPosition = RowIndex;
this.resultsGrid.Rows[RowIndex].Cells[ColName].Activate();
this.resultsGrid.Rows[RowIndex].Cells[ColName].Selected = true;
Can you explaing the second last line of code in above function; does Activate() function for an UltraGridCell returns a bool value, I tried it with a return bool variable (bool bResult = this.resultsGrid.Rows[RowIndex].Cells[ColName].Activate(); ) but bResult was always false, though the code works fine now...
I'm a little puzzled by the last line of code you have here. You are activating the cell twice... are you sure the second time is returning true? Maybe it returns false since the cell was already active and so the second call to Activate doesn't do anything.
The paste action deals with the Selected cell(s) in the grid and only works if AllowMultiCellOperation is on. So if you are pasting a value from one cell into another, you might be better off just setting the cell's Value.
I'm not sure why the grid is jumping back to the first row. Perhaps the grid is processing this code asynchronously and not updating the active cell until after the grid paints. Is the paste being performed synchronously in code or is the user taking some other action (like clicking a button) to do it?