Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSV import to Grid, 1st row header
#1
i created a dialog with a grid....  i am importing a  csv file into the Grid. The csv file has a header Row which i want to use as the Grid column header...

is there a way to either, tell the Grid that first row is column header or import from row 2 down... thanks
 
Code:
Copy      Help
ICsv csv._create
csv.Separator=","
csv.FromFile("C:\Logon\SavedActivity\UserAccess.csv")

DlgGrid g.Init(hDlg 3)
#2
I have a basic csv file that is structured like this
the first row is a header

ZIP,LAT,LNG
601,18.180555,-66.749961
602,18.361945,-67.175597
603,18.455183,-67.119887
606,18.158345,-66.932911
...
...
...

the file has has 33145  lines
 
Function DialogCSV_with_Header_To_QmGrid
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 QM_Grid 0x56031041 0x200 0 0 220 110 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3"
str qmg3x
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam
DlgGrid g.Init(hDlg 3)
sel message
,case WM_INITDIALOG
,ICsv v._create; ICsv v1._create
,v.Separator=","; v1.Separator=","
,v.FromFile("$documents$\deskfiles\geocodebyzip.csv");; change to file location
,int nr=v.RowCount
,int nc=v.ColumnCount
,str ms
,v.GetRowMS(0 ms);; get header row data
,v1.AddRowMS(-1 nc ms);; add to second Csv variable
,str s2; v1.ToString(s2);;convert to string so can add columns
,s2.findreplace("," "[]");; format string so ColumnsAdd function will work
,;g.ColumnsAdd(s2 1);;add columns to grid adjusting width  assuming there will be vertical scrollbar.
,g.ColumnsAdd(s2);; just add columns to grid will adjust  width later used in conjunction with line33
,v.RemoveRow(0);;remove header row from Csv
,v.ToQmGrid(g);; load csv into grid now that header row is removed
,g.ColumnsWidthAdjust;;adjust column width now ( used with g.ColummsAdd(s2) comment out if not needed)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#3
thanks, seems like alot of work for a header...

would be a nice feature to build it into the grid as an option under Properties, "When Getting Content". "use 1st row as column header" OR "start import from row___"

thanks for the reply.


Forum Jump:


Users browsing this thread: 1 Guest(s)