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

Highlighting editable columns

1 Answer 95 Views
This is a migrated thread and some comments may be shown as answers.
Pramod Goutham
Top achievements
Rank 1
Pramod Goutham asked on 24 Oct 2008, 01:42 PM

These might have already been posted. But I'm posting it again.

1. How do I highlight all the editable columns in the gridview so that the user can easily distinguish editable columns from non-editable columns?

2. How to perform any validations upon the text entered in editable cells when the focus is just lost from that cell (something similar to onfocuslost kind of event)?

3. I need to bind data to the combo box column in the gridview after a button (say a "search" button) is clicked. And I need to extract all the values selected in the grid combo box columns, upon clicking a (say "Submit") button.

Any help would be appreciated.

Pramod Goutham.

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 27 Oct 2008, 11:27 AM
Hello Pramod Goutham,

Thank you for your questions.

1) You can use the CellFormating event to change the formatting of certain cells. In the code snippet below all cells in the first column have their background color set explicitly:

private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)  
            e.CellElement.DrawFill = true;  
            if (e.CellElement.ColumnIndex == 0)  
                e.CellElement.BackColor = Color.LightBlue;  
                e.CellElement.BackColor2 = Color.LightBlue;  
                e.CellElement.BackColor3 = Color.LightBlue;  
                e.CellElement.BackColor4 = Color.LightBlue;  

2) About the validation please, review the following code snippet (ValueChanging event):

private void radGridView1_ValueChanging(object sender, ValueChangingEventArgs e)     
    if (this.radGridView1.CurrentCell.ColumnIndex == 0) {//applies to the 1st column     
           if (something ) { //use e.NewValue, e.OldValue for validation     
                e.Cancel = true//keep the oldvalue by canceling the event   

3) Please see the following sample code about adding a datasource and a combobox column:

DataTable t = new DataTable();  
t.Rows.Add(1, "A");  
t.Rows.Add(2, "B");  
t.Rows.Add(3, "A");  
this.radGridView1.MasterGridViewTemplate.AutoGenerateColumns = false;  
radGridView1.Columns.Add(new GridViewDecimalColumn("A"));  
GridViewLookUpColumn c = new GridViewLookUpColumn("B");//column B is the combobox one
c.DataSource = new String[] { "A""B""C" };  
this.radGridView1.DataSource = t; 

You may get the selected values using the following code:

foreach (GridViewRowInfo r in this.radGridView1.Rows) {  

Do not hesitate to contact me back if you have further questions.

Sincerely yours,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Pramod Goutham
Top achievements
Rank 1
Answers by
Telerik team
Share this question