S Smee Well-Known Member Licensed User Longtime User Jan 18, 2013 #1 I am using the table example with a database. i need to use a field returned from the database as a column header for col2 3 etc. How can i do this to replace the headers? Also there may be more than 4 cols. i will not know in advance. how can i build the string in the array. I tried stringbuilder but that does not work it treats the string as one column Code: Copy Table1.SetHeader(Array As String("Prod Code", "Description", "Col2", "Col3","Col4")) TIA
I am using the table example with a database. i need to use a field returned from the database as a column header for col2 3 etc. How can i do this to replace the headers? Also there may be more than 4 cols. i will not know in advance. how can i build the string in the array. I tried stringbuilder but that does not work it treats the string as one column Code: Copy Table1.SetHeader(Array As String("Prod Code", "Description", "Col2", "Col3","Col4")) TIA
mc73 Well-Known Member Licensed User Longtime User Jan 18, 2013 #2 I don't know about this custom table, but I suppose you can parse a list inside the setHeader. Upvote 0
S Smee Well-Known Member Licensed User Longtime User Jan 18, 2013 #3 Thanks for the reply but i want to also know how to dynamically build the Array As String part for other uses. Upvote 0
Thanks for the reply but i want to also know how to dynamically build the Array As String part for other uses.
M Mahares Expert Licensed User Longtime User Jan 18, 2013 #4 Here is what you need: Code: Copy txt = "SELECT Field1, Field2, Field3 FROM MyTable" Cursor1=SQL1.ExecQuery(txt) Dim Col_Name(3) As String For i=0 To Cursor1.ColumnCount-1 Col_Name(i)=Cursor1.GetColumnName(i) Next Col_Name = Array As String(Col_Name(0), Col_Name(1) , Col_Name(2)) Table1.SetHeader(Col_Name) Upvote 0
Here is what you need: Code: Copy txt = "SELECT Field1, Field2, Field3 FROM MyTable" Cursor1=SQL1.ExecQuery(txt) Dim Col_Name(3) As String For i=0 To Cursor1.ColumnCount-1 Col_Name(i)=Cursor1.GetColumnName(i) Next Col_Name = Array As String(Col_Name(0), Col_Name(1) , Col_Name(2)) Table1.SetHeader(Col_Name)
S Smee Well-Known Member Licensed User Longtime User Jan 18, 2013 #5 Thanks very much for the reply Mahares, looking at the code, that is very close to what i need and looks like it will work for the array part. However , Code: Copy Dim Col_Name(3) As String ... ... Col_Name = Array As String(Col_Name(0), Col_Name(1) , Col_Name(2)) shows that the number of columns is known in advance what i need is similar to Code: Copy Counter=cursor1.ColumnCount Dim Col_Name(Counter) As String for x= 0 to Counter Col_Name1=Col_Name1 & Col_Name(x) next Col_Name = Array As String(Col_Name1) Obviously this would not work but it should give you the idea of what i am trying to achieve. Any ideas? Many thanks Upvote 0
Thanks very much for the reply Mahares, looking at the code, that is very close to what i need and looks like it will work for the array part. However , Code: Copy Dim Col_Name(3) As String ... ... Col_Name = Array As String(Col_Name(0), Col_Name(1) , Col_Name(2)) shows that the number of columns is known in advance what i need is similar to Code: Copy Counter=cursor1.ColumnCount Dim Col_Name(Counter) As String for x= 0 to Counter Col_Name1=Col_Name1 & Col_Name(x) next Col_Name = Array As String(Col_Name1) Obviously this would not work but it should give you the idea of what i am trying to achieve. Any ideas? Many thanks
mc73 Well-Known Member Licensed User Longtime User Jan 18, 2013 #6 Code: Copy Dim Col_Name() As String Dim tempList As String For i=0 To yourCursor.ColumnCount-1 tempList=tempList & ",," & yourCursor.GetColumnName (i) Next Col_Name=Regex.Split (",,",tempList.SubString (2)) Table1.SetHeader(Col_Name) Upvote 0
Code: Copy Dim Col_Name() As String Dim tempList As String For i=0 To yourCursor.ColumnCount-1 tempList=tempList & ",," & yourCursor.GetColumnName (i) Next Col_Name=Regex.Split (",,",tempList.SubString (2)) Table1.SetHeader(Col_Name)
M Mahares Expert Licensed User Longtime User Jan 18, 2013 #7 Here is another solution where you do not need to know the number of columns in advance. You have choices: Code: Copy txt = "SELECT Field1, Field2, Field3 FROM MyTable" Cursor1=SQL1.ExecQuery(txt) Dim MyColCount As Int MyColCount=Cursor1.ColumnCount Dim Col_Name(MyColCount) As String For i=0 To MyColCount-1 Col_Name(i)=Cursor1.GetColumnName(i) Next Table1.SetHeader(Col_Name) Upvote 0
Here is another solution where you do not need to know the number of columns in advance. You have choices: Code: Copy txt = "SELECT Field1, Field2, Field3 FROM MyTable" Cursor1=SQL1.ExecQuery(txt) Dim MyColCount As Int MyColCount=Cursor1.ColumnCount Dim Col_Name(MyColCount) As String For i=0 To MyColCount-1 Col_Name(i)=Cursor1.GetColumnName(i) Next Table1.SetHeader(Col_Name)
mc73 Well-Known Member Licensed User Longtime User Jan 18, 2013 #8 Mahares said: Here is another solution where you do not need to know the number of columns in advance. You have choices: Code: Copy txt = "SELECT Field1, Field2, Field3 FROM MyTable" Cursor1=SQL1.ExecQuery(txt) Dim MyColCount As Int MyColCount=Cursor1.ColumnCount Dim Col_Name(MyColCount) As String For i=0 To MyColCount-1 Col_Name(i)=Cursor1.GetColumnName(i) Next Table1.SetHeader(Col_Name) Click to expand... You are absolutely right, Mahares, no need for the splits I performed earlier Upvote 0
Mahares said: Here is another solution where you do not need to know the number of columns in advance. You have choices: Code: Copy txt = "SELECT Field1, Field2, Field3 FROM MyTable" Cursor1=SQL1.ExecQuery(txt) Dim MyColCount As Int MyColCount=Cursor1.ColumnCount Dim Col_Name(MyColCount) As String For i=0 To MyColCount-1 Col_Name(i)=Cursor1.GetColumnName(i) Next Table1.SetHeader(Col_Name) Click to expand... You are absolutely right, Mahares, no need for the splits I performed earlier
S Smee Well-Known Member Licensed User Longtime User Jan 19, 2013 #9 Excellent, Thank you both for your help and efforts :icon_clap: Upvote 0