Hi
I want to export all the data from the UltraGrid including column headers to a Generic list. Could you please send some sample code for this?
It is quite urgent.
Thanks.
The code below will accomplish this. There might be a better way to do this, but at least this should get you going. Note that I'm assuming you have just one band, no grouping, etc. I used pipe as separator between columns.
Dim list As String = "" Dim line As String = "" Dim band As UltraWinGrid.UltraGridBand Dim row As UltraWinGrid.UltraGridRow Dim col As UltraWinGrid.UltraGridColumn Dim sortedCols As New ArrayList
band = myUltraGrid.DisplayLayout.Bands(0)
'Process the columns in the order they are in the grid col = band.GetFirstVisibleCol(myUltraGrid.ActiveColScrollRegion, True) Do While Not col Is Nothing 'Keep track of the order of the columns sortedCols.Add(col)
'This creates the first line which contains each column's text If line.Length > 0 Then line += "|" line += col.Header.Caption col = col.GetRelatedVisibleColumn(UltraWinGrid.VisibleRelation.Next) Loop list += line & vbCrLf
'Now put out values in same order as the headers above For Each row In myUltraGrid.Rows If Not row.Hidden Then line = ""
For Each col In sortedCols If line.Length > 0 Then line += "|" line += row.GetCellText(col) Next
list += line & vbCrLf End If Next
'This is the complete list MsgBox(list)
Thanks for the reply.
My UltraGrid is populated with the help of a domain object.
Ultragrid functions like this:
- the user can move the columns in the grid.
- the user can sort the column as per their need.
Now whatever changes done in the grid by the user we need to export it to a new Generic list.
I tried the below code to get the value from the grid but its returning the domain object name.
string s = grid.Rows[i].Cells[j].Value.ToString();
Could you send me a sample code for looping through the grid and putting it in new Generic list?
Another way to do it would be to simply loop through the grid rows and add each one to your list.
Do you mean you want a flat text file with the content?
The quickest way is probably to add UltraGridExcelExporter to your form and code like this:
UltraGridExcelExporter1.Export(Me.myUltraGrid, "c:\test.xls") Process.Start("c:\test.xls")
You now have the content of the grid in Excel and can export it from there in what ever form you need.
Trausti