Home Forums WinForms controls Xceed Grid for WinForms Prevent GridCell to show DateTime with GridDateTimePicker

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13732 |

    Hi,

    I have a System.Data.DataTable that I bind to a GridControl. One of the columns contains DateTime values. The GridControl choses to show the date not as a simple dd/MM/yyyy string. It shows the start of a GridDateTimePicker instead. The cell is ReadOnly so its contents will not need to be changed. I want the GridControl to just display the date, as a formated string.

    I tried setting the Cell or Column’s CellViewer (could not select GridTextBox, had to pick GridMaskedTextBox). I tried setting the Cell’s FormatProvider and FormatSpecifier properties. None of both helped.

    Thanks for pointing me into the right direction,
    Vincent

    Imported from legacy forums. Posted by panik (had 4667 views)

    User (Old forums)
    Member
    Post count: 23064

    Could you show us some code that shows this behaviour?

    Imported from legacy forums. Posted by Tommy (had 219 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    Nothing too fancy (I left some parts out, where I subscribe events to cells or to the InsertionRow etc.):

    DataViewGrid.BeginInit();
    DataViewGrid.DataSource = DataViewSet.Tables[0];

    Xceed.Grid.Editors.GridMaskedTextBox textboxEditor = new Xceed.Grid.Editors.GridMaskedTextBox();

    DataViewGrid.Columns[“Timestamp”].CellEditor = textboxEditor;
    //When I make the textboxEditor a Xceed.Grid.Editors.GridTextBox,
    //I can’t define the CellViewer with it
    DataViewGrid.Columns[“Timestamp”].CellViewer = textboxEditor;

    //This is the FormatProvider part I tried, think that could solve this problem
    foreach(Cell cell in DataViewGrid.DataRowTemplate.Cells)
    {
    if(cell.FieldName == “Timestamp”)
    {
    cell.FormatProvider = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat;
    cell.FormatSpecifier = “dd/MMM/yyyy HH:mm:ss”;

    //Makes the Cell ReadOnly, and makes it ‘look’ ReadOnly
    cell.ReadOnly = true;
    cell.ForeColor = Color.DarkGray;
    cell.CanBeCurrent = false;
    }
    }

    DataViewGrid.EndInit();

    Not sure how much this will make things clearer.

    Cheers,
    v

    Imported from legacy forums. Posted by panik (had 524 views)

    User (Old forums)
    Member
    Post count: 23064

    First of all, I don’t think you have to set the CellEditor or CellViewer of the column: if you don’t set them, a default CellEditor and CellViewer will be used.
    Second, you don’t have to loop through DataRowTemplate.Cells to find the Timestamp-cell. You can just get the cell like this: Cell cell = DataViewGrid.DataRowTemplate.Cells[“Timestamp”];

    Imported from legacy forums. Posted by Tommy (had 204 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    The default CellEditor and CellViewer is the whole point. I don’t want it. It renders a datetime picker. I want a simple display of the date. Not any control allowing me to change it, or that renders the date in a not standard way (a textbox, something that simple displays the date).

    cheers,
    v

    Imported from legacy forums. Posted by panik (had 454 views)

    User (Old forums)
    Member
    Post count: 23064

    I tried it out, and I got the DateTimePicker editor, when trying to edit a cell, but when not in edit mode, the GridControl would just display the date & time, like regular text.

    You could set the CellEditor & CellViewer properties of the column to <b>null</b>, to make sure there’s no editor or viewer attached to the column.

    Imported from legacy forums. Posted by Tommy (had 280 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    setting the CellEditor and CellViewer had the effect I wanted. Which is great. Thanks.

    v

    Imported from legacy forums. Posted by panik (had 5634 views)

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