Managing the ComboBox

2 posts, 0 answers
  1. Versile
    Versile avatar
    20 posts
    Member since:
    May 2009

    Posted 21 Aug 2009 Link to this post

    I'm trying to solve a couple of problems with using a combobox within my RadGridView and not sure if I have taken the most appropriate methods. So in either scenario, the code below might help someone else, but if this is not the way it was intended or of I'm missing something please let me know. I would much prefer to have all the combobox cells show the combobox live instead of when I "hover" or "click" on them.

    First Problem is I wanted all of my cells centered, they are dealing with numbers that look much better centered. Even though I set TextAlignment on the columns to MiddleCenter it did not seem to have any effect.

    Second Problem is I have a combobox column in the grid that I have successfully databound through some trial and error. The combo box shows text only when looking at it from the grid perspective and that annoys me, I want it to always be in "Edit" mode.Every attempt to turn all of them into edit mode caused the application to crash, so I settled for only showing one at a time by doing it on the mousemove and cellbeginedit methods.

    I added events for cellmousemove and cellbeginedit

    Code for Cell Mouse move is below (note that since I am changing the Text Alignment I'm being forced to set the color back to solid?)
    This activates the "Begin Edit" for the cell it's over if it has one of the values in my combobox.

    1         private void calendar_grida_CellMouseMove(object sender, MouseEventArgs e) 
    2         { 
    3             if (sender is GridDataCellElement) 
    4             { 
    5                 GridDataCellElement cInfo = (GridDataCellElement)sender; 
    6                 string cellValue = cInfo.Value.ToString().ToLower(); 
    7                 if (cellValue == "n/a" | 
    8                     cellValue == "open" | 
    9                     cellValue == "closed"
    10                 { 
    11                     cInfo.RowInfo.Cells["status_taken"].BeginEdit(); 
    12                 } 
    13             } 
    14         } 

    The problem now is if I change to another group it crashes the application with object reference not set to an object, to fix that I handle the cellBeginEdit event and cancel the beginedit if the currentcell is not the combobox

    1         private void calendar_grida_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) 
    2         { 
    3             string cellValue = this.calendar_grida.CurrentCell.Value.ToString().ToLower(); 
    4             if (cellValue == "n/a" | 
    5                 cellValue == "open" | 
    6                 cellValue == "closed"
    7             { 
    8                 return
    9             } 
    10             else 
    11             { 
    12                 e.Cancel = true
    13             } 
    14         } 

  2. Deyan
    Deyan avatar
    2147 posts

    Posted 26 Aug 2009 Link to this post

    Hello Versile,

    Thanks for writing and for your questions.

    Currently, it is not possible have all cells in a column show a RadComboBox since the RadGridView control only uses one editor at a time, i.e. when you have an editor opened in a cell, you cannot have another editor opened in another cell.

    The TextAlignment property of a Grid View Column should work. I have tested it by creating a simple Windows Forms application that has a RadGridView on a RadForm and sets the alignment of the fifth column to MiddleCenter in the OnLoad event of the Form:

    this.radGridView1.Columns[4].TextAlignment = ContentAlignment.MiddleCenter; 

    However, if you continue experiencing difficulties when setting the alignment of a column, please open a new support ticket and send me a small Windows Forms application that reproduces the issue so that I can take a look at it and provide you with help.

    Thanks for your time.

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top