Hi,
Is there an Excel like row header where I can display row index regardless of sort and filtering? I tried adding a column with row.visibleIndex but then the data would have to be added after sort and it seems a bit awkward. Furthermore I would like the row index column to NOT be part of the grid data so I wouldn't have to filter it out when exporting etc.
Thanks, David
Sorry about that. I specifically set the DataType on the column to Integer so that would not happen. But apparently, the InitializeRow was triggered by the adding of the column (before I set the DataType). So when InitializeRow sets the Value on the cell to an integer, it got converted into a string, which is the default DataType of the column.
So you can get around that by not using InitializeRow and just looping through the cells after the DataType on the column is established.
I've attached an updated sample here in case you are interested. But there's nothing wrong with your approach using CellExported, either.
Thank you for the solution. It worked great. Only thing is, the excel row number is coming over as text instead of an integer so in excel you get the "[number stored as text]" warning on the cells.
I ended up adding a column to the "export started" event...
' Add new row count column
e.Layout.Override.AllowAddNew = AllowAddNew.Yes
e.Layout.Bands(0).Columns.Insert(0, "cnt").Header.Caption = "[row #]"
e.Layout.Bands(0).Columns(0).Width = 40
And then on "cell exported", increment each row value..
' Add row #
If excelCell.Value Is Nothing Then
For Each row As WorksheetRow In e.CurrentWorksheet.Rows
e.CurrentWorksheet.Rows(e.CurrentRowIndex).Cells(e.CurrentColumnIndex).CellFormat.Alignment = HorizontalCellAlignment.Center
excelCell.Value = i
i += 1
Next
End If
If you read the third post down from the top, I explained a couple of possible methods for doing that. Personally, I'd probably go with the unbound column approach.
I've attached a quick sample for you here to demonstrate how it's done.
Can you tell me how to add row numbers to the excel doc?
I'm using the following to add row numbers to my ultragrid. but the excel isn't exporting w/row numbers:
e.Layout.Bands(0).Override.RowSelectorNumberStyle = RowSelectorNumberStyle.RowIndex e.Layout.Bands(0).Override.RowSelectors = Infragistics.Win.DefaultableBoolean.True e.Layout.RowSelectorImages.ActiveAndDataChangedImage = Nothing Me.Grid.DisplayLayout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.SeparateElement
Hello,
That is exactly what I am trying to accomplish;
"made me think you were exporting the grid to Excel and wanted to export row numbers there"