View previous topic :: View next topic |
Author |
Message |
Harri Guest
|
Posted: Mon May 09, 2005 9:44 am Post subject: Retrieve RowWidget & StartEdit()-method |
|
|
Hello,
I’m trying to achieve the following with the vitual tree component:
When a user selects a row in the virtual tree, the first editable cell of the row should be edited as soon as the user starts typing (currently the user first needs to click on the cell to edit the cell). Using the tab-key, it jumps to the next row (this is already the default behaviour); this next row’s first editable cell is then ready for editing as soon as the user starts typing. However, some of the rows do not have an editable cell in the row. Pressing tab again should then move to the next row (this is not default behaviour).
I’m trying to do this with the Rowwidget.GetFirstEditableCellWidget().StartEdit()-method of the VirtualTree.SelectedRow. However I did not find a way to retrieve the RowWidget. Is this the right way to do achieve above described functionality and if so, how can I retrieve the RowWidget for the current SelectedRow?
Thank you in advance for your answer,
Harri. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon May 09, 2005 10:40 pm Post subject: |
|
|
There is currently no method on VirtualTree to programmatically start editing a cell. You could however create a derived class and add one as follows:
Code: |
public void StartEdit(Row row)
{
this.SelectedRow = row;
RowWidget rowWidget = this.GetRowWidget(row);
EditWidget = rowWidget.GetCellWidget(_folderColumn);
}
|
Alternatively you could set the display mode for the editor to be "Always" so that the editors are shown always.
Changing tab behaviour so that it skips rows that don't have an editable cell is a little more difficult because you would have to decide how many rows you are going to skip - for instance if there are 200 rows without an editable cell - are you going to scroll that far? Your particular application however may have some constraints that mean this is not an issue. To change this behaviour you would need to override the EditNext and EditPrior methods.
Below is the code for the default EditNext method - so you know the logic you would have to implement:
Code: |
/// <summary>
/// Edit the next cell widget in the tab order
/// </summary>
/// <returns>True if there was a widget to move to</returns>
protected virtual bool EditNext()
{
CellWidget cellWidget = null;
if (EditWidget != null)
{
Column column = EditWidget.Column;
cellWidget = EditWidget.RowWidget.GetNextEditableCellWidget(column);
}
if (cellWidget == null)
{
if (MoveFocusRow(1, KeyboardSelectionMode.MoveSelection, false))
{
RowWidget rowWidget = GetRowWidget(FocusRow);
if (rowWidget != null)
{
cellWidget = rowWidget.GetFirstEditableCellWidget();
}
}
}
if (cellWidget != null)
{
EnsureColumnVisible(cellWidget.Column);
}
EditWidget = cellWidget;
return (cellWidget != null);
}
|
_________________ Infralution Support |
|
Back to top |
|
|
Harri Guest
|
Posted: Tue May 10, 2005 11:29 am Post subject: |
|
|
Thank you for your answers!
Keep up your good and quick support, it's highly appreciated over here. With the help of your answer, I've managed to get it working.
If you like I could post the code-snippits of my solution here to share my experience... |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue May 10, 2005 10:37 pm Post subject: |
|
|
Sure that would be great - it may help others attempting similar things _________________ Infralution Support |
|
Back to top |
|
|
Harri Guest
|
Posted: Thu May 12, 2005 6:57 am Post subject: |
|
|
Here it is. Once in edit-mode, press (shift-)tab will scroll and edit the next(/previous) editable row.
Code: |
/// <summary>
/// Edit next editable-row.
/// </summary>
/// <returns></returns>
protected override bool EditNext()
{
// First cache current selected row
Row cr = this.SelectedRow;
// We keep on trying to editNext until we found a row
// that is editable (EditNext() returns true).
// If we enter the last row and still not editable,
// we'll go back to the cached current selected row
while (!base.EditNext())
if (this.IsLastRow(this.FocusRow))
return StartEditRow(cr);
return true;
}
/// <summary>
/// Edit the previous editable-row
/// </summary>
/// <returns></returns>
protected override bool EditPrior()
{
// First cache current selected row
Row cr = this.SelectedRow;
// We keep on trying to editPrior until we found a row
// that is editable (EditNext() returns true).
// If we enter the first row and still not editable,
// we'll go back to the cached current selected row
while (!base.EditPrior ())
if (this.FocusRow.IsTopRow)
return StartEditRow(cr);
return true;
}
/// <summary>
/// Selects and edit the specified row (if editable)
/// </summary>
/// <param name="row"></param>
/// <returns>true if editable</returns>
private bool StartEditRow(Row row)
{
this.SelectedRow = row;
RowWidget rowWidget = GetRowWidget(FocusRow);
if (rowWidget != null)
{
CellWidget cellWidget = rowWidget.GetFirstEditableCellWidget();
if (cellWidget != null)
EnsureColumnVisible(cellWidget.Column);
EditWidget = cellWidget;
return true;
}
return false;
}
/// <summary>
/// Check if the row is the last row
/// </summary>
/// <param name="row"></param>
/// <returns></returns>
private bool IsLastRow(Row row)
{
if (row.RowIndex == this.LastRowIndex)
return true;
return false;
}
|
To enter in 'edit-mode' I used the F2-key:
Code: |
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode.Equals(Keys.F2))
{
this.EditNext();
e.Handled = true;
}
base.OnKeyDown (e);
}
|
Regards,
Harri |
|
Back to top |
|
|
|