Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
405
Setting Row colour
posted

hi ,

I want to set   background of the highlighted clumn,

because if i select a row in grid it gets highlighted but the column on which my cursor is

having some other background and foreground color,also i want to make my grid readonly not edit able , thanks.

 

  • 3565
    Suggested Answer
    posted

    Given if I had to do what you are asking this is how I would do it today. Not to say that there isn't some other fancy way to do it. I would not be surprised given all the bells and whistles in the WinGrid.

    To set the grid as read-only to the user change the allowupdate, allowedit and allowdelete properties to false. You do this in the grid properties window by going to DisplayLayout -> Override and updating the AllowAddNew, AllowUpdate and AllowDelete properties or in the feature picker in the UltraGrid designer.

    At run time you can do the same thing.

            Grid.DisplayLayout.Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.No
            Grid.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.False
            Grid.DisplayLayout.Override.AllowDelete = Infragistics.Win.DefaultableBoolean.False

    To update the current selected cells column highlight I used the cell click event updated the cell's column CellAppearance.BackgroundColor property to another column. But if you want the previous column to change back after you leave you have to save that information somewhere. I just saved that information using the target object's tag property.

        Private Sub Grid_ClickCell(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.ClickCellEventArgs) Handles Grid.ClickCell
            Dim Grid = CType(sender, Infragistics.Win.UltraWinGrid.UltraGrid)
            Dim CurrentCell = e.Cell
            Dim CurrentColumn = CurrentCell.Column

            'Check for last cell/column to change it back
            If Grid.Tag IsNot Nothing Then
                If TypeOf Grid.Tag Is Infragistics.Win.UltraWinGrid.UltraGridColumn Then
                    'Found last grid column
                    Dim PreviousColumn = CType(Grid.Tag, Infragistics.Win.UltraWinGrid.UltraGridColumn)
                    If TypeOf PreviousColumn.Tag Is Infragistics.Win.Appearance Then
                        'Found the last column appearance
                        PreviousColumn.CellAppearance = CType(PreviousColumn.Tag, Infragistics.Win.Appearance)
                    End If
                End If
            End If

            'Remember the current column for later
            Grid.Tag = CurrentColumn

            'Save the existing column appearance for later
            CurrentColumn.Tag = CurrentColumn.CellAppearance

            'Update the current cells column to alternate color
            'Would be better to use same appearance object and define it global to this method
            Dim Appearance As New Infragistics.Win.Appearance With {.BackColor = Color.Yellow}
            CurrentColumn.CellAppearance = Appearance
        End Sub