Hi IG,
I have this code:
private void _grid_KeyDown(object sender, KeyEventArgs e){ //delete key = clear the current cell if (e.KeyCode == Keys.Delete || e.KeyCode == Keys.Back) { if (0 == (_grid.CurrentState & UltraGridState.InEdit)) if (_grid.ActiveCell != null) if (_grid.ActiveCell.Value is CellClass) (_grid.ActiveCell.Value as CellClass).Clear(); }}
The problem is, the cell is not refreshed/repainted until you move the mouse over, or scroll/resize the column, etc. Cell is displayed as string, and CellClass has ToString() via IConvertible.
I tried adding BeginInvoke() around -> no success.I tried _grid.ActiveCell.Refresh() -> no success.I tried _grid.Invalidate(_grid.ActiveCell.GetUIElement().Rect) -> no success.I tried reassign the same value to the ActiveCell -> no success.I debugged, and the ActiveCell.Text immediately changes to "" after calling Clear().
What could be the problem? Thanks.
Hello Michael,
Thank you for contacting Infragistics Support.
In order to give you my best possible solution for your issue can you please give me a little more information regarding your case:
1) How you have implemented your CellClass?
2) Have you implemented INotifyPropertyChangedinterface in your CellClass?
3) Did you call the PropertyChanged event in your custom CellClass?
It will help if you can provide a small, isolated sample application that demonstrates the behavior you are experience.
Waiting for your feedback.
Hi Milko,
Thanks for your help.
This is how grid is used:
class CellClass : IConvertible{ public String DisplayValue = ""; public MyClass RealValue = null; public CellClass(String displayValue, MyClass realValue) { DisplayValue = displayValue; RealValue = realValue; } public SetValue(String displayValue) { RealValue = Parse(displayValue); DisplayValue = RealValue.AsString(); }
#region IConvertible Members public object ToType(Type conversionType, IFormatProvider provider) { return Convert.ChangeType(DisplayValue, conversionType); } public TypeCode GetTypeCode() { return TypeCode.Object; } public string ToString(IFormatProvider provider) { return DisplayValue; } //rest of IConvertible just throw new NotImplementedException(); #endregion internal void Clear() { DisplayValue = ""; RealValue = null; }}void BuildGrid(){ _gridSource.Rows.Clear(); _gridSource.Band.Columns.Clear(); for (x = ....) { UltraDataColumn col = _gridSource.Band.Columns.Add(name[x], typeof(Object)); UltraGridColumn gridCol = _grid.DisplayLayout.Bands[0].Columns[_grid.DisplayLayout.Bands[0].Columns.Count - 1]; gridCol.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Edit; }}void LoadData(){ List<object> row = new List<object>(); foreach (......) { row.Add(new CellClass ("", new MyClass(...))); } _gridSource.Rows.Add(row.ToArray());}
The principal is that, we are storing own class in every cell of the grid (Object / CellClass), but displaying them as String.
When user edits cells, we are parsing the new String value, and converting it to CellClass.
Indeed, that's the reason.
Thanks your help!
Thank you for your feedback.
Here is a little more info regarding your findings:
1. Update 1 – before calling Clear method to your CellClass you have an UltraGridCell which value refers to an instance of CellClass, let’s call it MyCellClassInstance. After calling the Clear method you are setting to null one property of the MyCellClassInstance. This does not change the value of the UltraGridCell – it is still refers to MyCellClassInstance, nevertheless the last was changed internally. When you create a new CellClass instance, let’s call it CurrentCellClassInstance and set the UltraGridCell value to this new object you are actually changing the cell value. This is why it forces the grid to refresh.
2. Update 2 – the reason UltraGrid does not refresh here are absolutely the same. The value of the UltraGridCell is not changed. This is why I am explicitly call Refresh method of the row.
Please let me know if you have any additional questions.
Thanks Miko.
However, there is no issue with custom class <> grid cooperation, except when changing the cell.Value in the keydown event handler will change the cell.Text immediately to "", but not on the GUI (so no repaint happens), until I "force" it to refresh redraw, as hovering the mouse over, scrolling the grid, resize, etc.
Update 1
Btw, I found a workaround with the current implementation:
instead of(_grid.ActiveCell.Value as CellClass).Clear();
using:CellClass current = (CellClass)_grid.ActiveCell.Value;current.Clear();_grid.ActiveCell.Value = new CellClass(current);will reflect on the GUI immediately.
Update2
I just went through your sample, and I found what you do:
this.ultraGrid.ActiveCell.Row.Refresh();
without this, your sample also does not refresh the GUI immediately, I tried.So now there are 2 solutions, mine in Update1, and your one in Update2.Regarless, I will consider to use IEditorDataFilter instead of "custom" converting in _gridSource_CellDataUpdating().
Thank you for your help.
If I understand you correctly you need to convert your custom class and display it in the grid cell as a string as well as convert the user’s input value from string to your custom class. In order to achieve such behavior you can use IEditorDataFilter interface. More about this interface you may find by following the next link http://help.infragistics.com/Help/Doc/WinForms/2014.2/CLR4.0/HTML/WinGrid_Using_the_IEditorDataFilter_Interface_with_WinGrid.html
Please find attached a sample solution implementing this approach.
Please let me know if this is what you are looking for or if I am missing something.