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

color the background of a cell

3 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shirya
Top achievements
Rank 1
Shirya asked on 05 Dec 2008, 09:24 PM
Hello,
Could you help me with this:
When a cell is selected in my grid, i would like its backcolor to change to "Selected color".
And when another cell is clicked, the previous cell change its backColor to "Original color".

All of this is working when I  insert this code:
Private Sub GridViewPrepack_CellClick(ByVal sender As System.ObjectByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles GridViewPrepack.CellClick 
        'Get the right cell and the columnName 
        Dim myNewSelectedCell = CType(sender, GridCellElement) 
        Dim columnName As String = myNewSelectedCell.ColumnInfo.HeaderText 



        GridViewPrepack.CurrentRow.Cells(columnName).CellElement.BackColor = Color.Red 
       
    End Sub 
 
Here is what i don't know how to do:
There is a commandCell in my grid, and I when i click on it, i want the color of my previous selected cell to stay to "Selected color"
I try to put a condition saying : " if its the command cell, leave my previous selected cell colored"
But it doesn't work.
Can you tell me how to do it?
thank you

3 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 08 Dec 2008, 04:59 PM
Hi Shirya,

Thank you for your question. Please see the code snippet below. If you click on a command button it sets the current row to the previous current row:

Private Sub radGridView1_CommandCellClick(ByVal sender As ObjectByVal e As EventArgs) 
    Me.radGridView1.CurrentRow = oldRow 
 
End Sub 
Private oldRow As GridViewRowInfo 
Private Sub radGridView1_CurrentRowChanged(ByVal sender As ObjectByVal e As CurrentRowChangedEventArgs) 
    oldRow = e.OldRow 
End Sub 
 

Do not hesitate to write me back if you have more questions.

Sincerely yours,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shirya
Top achievements
Rank 1
answered on 10 Dec 2008, 04:06 PM
hello,
thank you for the answer, but i don't know if the solution you suggest can help me.
I try to use your code , replacing the currentRow by currentCell, but it is ReadOnly...
I want to change the currentCell( when its a commandCell) to the previous currentCell.
how can i leave the backColor of a cell to red, when the next Cell clikced is a commandCell?
i hope i'm clear (sorry for my english)
thank you
Shirya
0
Nick
Telerik team
answered on 11 Dec 2008, 02:08 PM
Hello Shirya,

Sorry for misunderstanding you.

Does the code below cover your scenario:

private void radGridView1_CommandCellClick(object sender, EventArgs e) 
        { 
            GridCommandCellElement commandCell = (GridCommandCellElement)sender; 
            commandCell.BackColor = Color.Red; 
            commandCell.DrawFill = true
        } 
        GridViewColumn currentColumn; 
 
        private void radGridView1_CurrentCellChanged(object sender, Telerik.WinControls.UI.CurrentCellChangedEventArgs e) 
        { 
            if (e.NewCell != null && e.NewCell is GridCommandCellElement) 
            { 
                this.radGridView1.CurrentColumn = currentColumn; 
            } 
            currentColumn = this.radGridView1.CurrentColumn; 
        } 

Do not hesitate to write me back if you have more questions.

Best wishes,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Shirya
Top achievements
Rank 1
Answers by
Nick
Telerik team
Shirya
Top achievements
Rank 1
Share this question
or