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.
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
That's a good way to do it. Although, personally, I would use the AfterCellActivate event instead of ClickCell. That way, it will work when the ActiveCell changes without clicking - like via the keyboard.
Also, this KB article may help: HOWTO:How can I make a grid or a column, row, or cell in the UltraWinGrid disabled or read-only?
Well, just to be clear... if you set AllowUpdate to false and AllowDelete to true, users will be able to delete rows, but not edit them.
But as I said, AllowDelete and AllowAddNew default to off.
Ah... good to know. I assumed that if you set AllowUpdate the grid would still allow add and delete. I had to worry about this recently because I'm using a grid as summary report in my current project that I didn't want users to be able to modify.
Well, deleting is disabled by default, as is adding new rows. So all you would have to do is set AllowUpdate to False.
And there is always the Enabled, property, of course. But that's probably not what you want, since it disabled everything including sorting, scrolling, etc.
If you wanted a grid to be totaly read-only ie. - no adds, updates, or deletes there wouldn't happen to be some sort of global read-only property would there?