Hello,
This is a follow up to a previous post : http://es.infragistics.com/community/forums/p/85559/426927.aspx#426927
I have an UltraGrid that has a number of bands (as discussed in the above thread). After we re connect the datasource to the grid, an InitializeRow event is fired. In this event I attempt to activate a specific cell, doing something like:
selectedRow.Cells[cellIndex].Activate(); UltraGrid.PerformAction(UltraGridAction.ActivateCell);
The selected row is one of the child bands (as described in prev thread) and in the debugger (VS2010 C#) I see the selectedRow belongs to the band I want and cellIndex is a valid cell within the row.
The problem is once the row is initialized the cell is not selected; ie. it does not look like a user clicked it manually.
The only "Activation" properties I set are in the InitialzeRow event handler e.Row.Activation = Activation.NoEdit;
and this is done before attempting to Activate call on the cell.
Any suggestions?
Thanks.
Ok, got this working, it looks like I needed to set the color, before I could actually see the cell was selected??? I'm dong this now in the initalizeRow event handler and this works (note the "_selected..." parameters are set in another method, basically indicate the cell I want to programmatically activate/select:
UltraGridChildBand sampleBand = rootRow.ChildBands[_selectedSampleBandIndex]; UltraGridRow selectedRow = sampleBand.Rows[_selectedRowIndex];
UltraGridCell ultraGridCell = selectedRow.Cells[_selectedColumnIndex]; ultraGridCell.IgnoreRowColActivation = true; ultraGridCell.Activation = Activation.NoEdit;
ultraGridCell.ActiveAppearance.ForeColor = UltraGrid.DisplayLayout.DefaultSelectedForeColor; ultraGridCell.ActiveAppearance.BackColor = UltraGrid.DisplayLayout.DefaultSelectedBackColor;
UltraGrid.ActiveRow = selectedRow; UltraGrid.ActiveCell = ultraGridCell; UltraGrid.PerformAction(UltraGridAction.ActivateCell, false, false);
Next issue: when the user selects a cell from this same row, the first cell remains selected. I've tried deactivating the previous cell (by storing it in a new set of "_prevSelected..." variables in the ClickEvent) then using the UltraGridAction.Deactivate cell. So question is, proper way to "deactivate" previously selected cell. Also note, the datasource may be disconnected and reconnected between first and second selection.
Thanks again.
Frank,
When you activate a cell the previously activated cell automatically becomes deactivated. There can only be one active cell at a time. You don't need to do anything to "deactivate" the previously selected cell. You are probably seeing the color of the ActiveRow and not the color of the ActiveCell. You could try setting the BackColor of the ActiveRowAppearance property (in the Override) to something different in order to demonstrate this for yourself.
Thanks for your reply Michael,
I still cannot get the cell activation to work. I've simplified the code to test
a) the when I click on a cell I store the row and column index as
private void ClickedUltraGridCell(UltraGridCell cell)
{
_columnIndex = cell.Column.Index; _rowIndex = cell.Row.Index;
...
in the UI the cell is highlighted.
b) in my code I disconnect/reconnect the UltraGrid datasource, to display a different set of data based on another user action.
c) I attempt to re-select the same cell location (note: the datasources look identical its basically different numbers in different tables):
UltraGridRowInitialize(object sender, InitializeRowEventArgs e)
if(_rowIndex == e.Row.Index) { var ultraGridCell = e.Row.Cells[_columnIndex]; UltraGrid.ActiveRow = e.Row; UltraGrid.ActiveCell = ultraGridCell;
performAction = UltraGrid.PerformAction(UltraGridAction.ActivateCell); }
This action does NOT reselect the previous selected cell.
Any suggestions as to why not?
I don't think you want to reset the data source in the InitializeRow event. I have attached a sample application in which I reset the datasource of the grid in a ButtonClick event and then activate the cell that corresponds to the cell that had been previously activated. Actually, I am calling the PerformAction method and forcing the grid to enter edit mode. Take a look at this sample and let me know if this gives you the functionality that you want. Run the application in Visual Studio 2012 and click on one of the cells to put it into edit mode. Then click the "Re-assign Data Source" button and you should see that even though the data in the grid has changed the same cell will be activated and in edit mode. Let me know what you think.
Thank you for the sample code. I am using VS2010 so cannot load it directly, but did look at the files. I could not implement them as-is since I have a hierarchical structure. The "Root" may have several child bands.
I did the following:
void UltraGridInitializeLayout(object sender, InitializeLayoutEventArgs e)
e.Layout.Override.CellClickAction = CellClickAction.EditAndSelectText;
e.Layout.Override.RowSelectors = DefaultableBoolean.True;
}
void ReassignDataSource()
UltraGrid.DataSource = NewGridDataSource;
if (_columnIndex > 8) //for testing I know I click above 8th column { UltraGridRow parentRow = UltraGrid.Rows[_rootBandIndex]; UltraGridRow childRow = parentRow.ChildBands[0].Rows[_childBandIndex]; childRow.Cells[_columnIndex].Activate(); UltraGrid.PerformAction(UltraGridAction.EnterEditMode); }
void UltraGridAfterCellActivate(object sender, EventArgs e) { _rootBandIndex = UltraGrid.ActiveRow.ParentRow.Index; _childBandIndex = UltraGrid.ActiveRow.Index;
_columnIndex = UltraGrid.ActiveCell.Column.Index;
The above code did not work at all for me. It does work ONCE if I move the code in the above "ReassignDataSource" fcn into the UltraGridInitializeRow fcn instead; the 2nd time I select a cell then switch DataSource, the cell is not highlighted.
I also find: a) AfterRowUpdate even is never fired b) cannot use ActivateCell instead of EnterEditMode (I don't want user to edit the cell just highlight it)
Thanks,
Frank
I didn't realize you were working with hierarchical data. That does make it more complicated. I have attached a new sample to the case. This one is built using Visual Studio 2010. I believe it does what you described. In this sample I am assuming that your grid has only two levels of hierarchy. If you have more than that then you will have to add on to this logic. Check it out and let me know what you think.
Hi Michael,
Thanks for the project it helped point me in the right direction. After experimenting I found that Activating the cell was not exactly what I wanted nor did I want to EnterEditMode on the cell. So I ended up storing the cell before the dataSource was changed, then re-applying it by using the UltraGrid.Selection.Cells.Add() fcn. This provides the blue background within the cell.
Best Regards.