Hey guys,
First and formost, this may not be an actual bug - there's a good chance I'm doing something a little bit abnormal.
I have a RadGridView (named gvwManifestLines) with these three columns:
GridViewTextBoxColumn lengthColumn = new GridViewTextBoxColumn(); | |
lengthColumn.UniqueName = "LengthColumn"; | |
lengthColumn.HeaderText = "Length"; | |
lengthColumn.DataType = typeof(Int32); | |
lengthColumn.FieldName = "itemLength"; | |
lengthColumn.FormatString = "{0}cm"; | |
this.gvwManifestLines.Columns.Insert(i++, lengthColumn); | |
GridViewTextBoxColumn widthColumn = new GridViewTextBoxColumn(); | |
widthColumn.UniqueName = "WidthColumn"; | |
widthColumn.HeaderText = "Width"; | |
widthColumn.DataType = typeof(Int32); | |
widthColumn.FieldName = "itemWidth"; | |
widthColumn.FormatString = "{0}cm"; | |
this.gvwManifestLines.Columns.Insert(i++, widthColumn); | |
GridViewTextBoxColumn heightColumn = new GridViewTextBoxColumn(); | |
heightColumn.UniqueName = "HeightColumn"; | |
heightColumn.HeaderText = "Height"; | |
heightColumn.DataType = typeof(Int32); | |
heightColumn.FieldName = "itemHeight"; | |
heightColumn.FormatString = "{0}cm"; | |
this.gvwManifestLines.Columns.Insert(i++, heightColumn); |
I am handling that gridview's CellFormatting event as follows:
private void gvwManifestLines_CellFormatting(object sender, CellFormattingEventArgs e) | |
{ | |
GridViewCellInfo cellInfo = this.gvwManifestLines.Rows[e.CellElement.RowIndex].Cells[e.CellElement.ColumnIndex]; | |
if (e.CellElement.ColumnIndex == this.gvwManifestLines.Columns["LengthColumn"].Index || | |
e.CellElement.ColumnIndex == this.gvwManifestLines.Columns["WidthColumn"].Index || | |
e.CellElement.ColumnIndex == this.gvwManifestLines.Columns["HeightColumn"].Index) | |
{ | |
if (cellInfo.Value == null || | |
cellInfo.Value is DBNull || | |
(int)cellInfo.Value <= 0) | |
{ | |
e.CellElement.FormatString = "n/a"; | |
} | |
} | |
} |
Essentially, I am using the length, width, and height values to calculate the volume per line in the volume column (omitted). I am doing a calculation in the grid's CellEndEdit for the length, width, height, and volume columns that will allow the user to either a) fill in length, width, and height to calculate the volume, or b) just enter in the volume and have the length, width and height ignored.
My implementation for this is to treat a value of '0' in the length, width or height column as a signifier that the calculation should ignore those three fields. However, it is confusing to have 0cm * 0cm * 0cm = 1000cm^2, so in the case of 0cm I want the display format to show as 'n/a'. It has a nicer feel.
This all works fine. The only problem is that when I pass the mouse over a cell that contains an 'n/a', the cell reverts back to '0cm' again until I click somewhere in the grid. There's a good change that the user will be doing a lot of back-and-forth waiving of the mouse around in the app, and this just looks sloppy.
What I wanted to do was to move my code in the CellFormatting handler into a private method, and then recall this method from within the CellMouseMove event. However, I am unsure how to use the MouseEventArgs to extract the relevant cell's row and column index information from the grid.
Additionally, there could be a better solution to this problem - I'm all ears!
Essentially, this isn't mission critical. It can wait for a bit, so I'm not going to be too worried about tinkering my way to a solution. I figure I'd just post here and see what comes up.