Home Forums WPF controls Xceed DataGrid for WPF Set selected Cell content to default value when pressing 'del'

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • simon
    Participant
    Post count: 2
    #44177 |

    Hello,

    when my Row is in EditMode and I tab though my cells, so one cell is selected. When I press ‘del’ I want to change the current cell content to it’s default Value (i.e. 0 for int and null for int?).
    How can I do this?

    Right know the cell.Content.GetType() gets me int even when the underlying Property is of Type Nullable<int>?

    Any suggestion how I can get the real Type of the underlying Property of the cell content, or how I otherwise can do this Action?

    Thanks
    Simon

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi,

    I am not sure if I understood what you meant. Could you send me a simple stand alone sample project which reproduces the issue so that I could have a closer look.

    simon
    Participant
    Post count: 2

    Hi,

    thanks for the response I try to explain my problem further with some sample code:

    When the Delete Key is pressed, I call the following method (_dataGridControl is my DataGridControl):

    public void DeleteCell()
    {
    	if (_dataGridControl.IsBeingEdited && !_dataGridControl.CurrentColumn.ReadOnly)
         {	
    		var row = _dataGridControl.CurrentContext.GetContainerFromItem(_dataGridControl.CurrentItem) as DataRow;
    		var cell = row.Cells[_dataGridControl.CurrentColumn.Index];
    	
    		if (cell.IsEditable())
    		{
    			cell.BeginEdit();
    			if (cell.Content != null)
    			{							
    				Type cellDataType = cell.Content.GetType();
    				if (cellDataType == typeof (string))
    				{
    					cell.Content = string.Empty;
    					return;
    				}		
    				if(cellDataType.IsValueType && Nullable.GetUnderlyingType(cellDataType) == null)
    				{
    					cell.Content = Activator.CreateInstance(type);
    					return;
    				}
    				cell.Content = null;
    			}
    		}
         }
    }

    The Problem is that when the Type of the underlying Property is a Nullable Valuetype (for example int?), cell.Content.GetType(); gives me the not Nullable Valuetype (for example int).
    So my question is how do I get the real Type of the underlying Property?

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.