This is a migrated thread and some comments may be shown as answers.

Managing the ComboBox

1 Answer 87 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Versile
Top achievements
Rank 1
Versile asked on 21 Aug 2009, 10:59 PM
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.

        private void calendar_grida_CellMouseMove(object sender, MouseEventArgs e) 
        { 
            if (sender is GridDataCellElement) 
            { 
                GridDataCellElement cInfo = (GridDataCellElement)sender; 
                string cellValue = cInfo.Value.ToString().ToLower(); 
                if (cellValue == "n/a" | 
                    cellValue == "open" | 
                    cellValue == "closed"
                { 
                    cInfo.RowInfo.Cells["status_taken"].BeginEdit(); 
                } 
            } 
        } 

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

        private void calendar_grida_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) 
        { 
            string cellValue = this.calendar_grida.CurrentCell.Value.ToString().ToLower(); 
            if (cellValue == "n/a" | 
                cellValue == "open" | 
                cellValue == "closed"
            { 
                return
            } 
            else 
            { 
                e.Cancel = true
            } 
        } 


1 Answer, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 26 Aug 2009, 03:49 PM
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.

Regards,
Deyan
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.
Tags
GridView
Asked by
Versile
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Share this question
or