Just learning how to use TIWAdvWebGrid and have problems dynamically adding columns.
I'm trying to make a simple program, allowing me to enter a SQL select as an edit, call an ADO Query, and depending on the result, show rows and columns, in a TIWAdvWebgrid. I know I could use a DB aware grid, but I do not want to.
where rows can be added just by increasing the Rowcount it's a bit more tricky with adding columns.
If I have a q1.fieldcount -1 of 5, how do I create 5 columns dynamicly ?. There are no columns in the grid at start.
I see now some of the text is out of context and do not really make any sense. Sorry for that. What I meant was to say that creating columns in code is easier wit a standard grid where it's a question of setting ColCount.
But please do not notice. My need is how to add columns in code, starting with an empty grid.
Thanks. columns.add is what I use. It just gave me some problems in the beginning:
II was using this:
for i := 0 to q1.fieldcount -1 do begin AWG1.Columns.Add; AWG1.Columns[ i ].Name := 'Col'+i.ToString; AWG1.Columns[ i ].Title := q1.fields[ i ].fieldname; AWG1.Columns[ i ].AllowSizing := false; If i = 0 then AWG1.Columns[ i ].ColumnType := ctLink; If i > 0 then AWG1.Columns[ i ].ColumnType := ctNoWrap; AWG1.Columns[ i ].Width := GetTextLength(q1.fields[ i ].fieldname+'M');
end;
However, all columns ended up with the same properties. Not until I separated the adding from the property setting like below, did it work:
for i := 0 to q1.fieldcount -1 do begin AWG1.Columns.Add;
end;
for i := 0 to q1.fieldcount -1 do begin AWG1.Columns[ i ].Name := 'Col'+i.ToString; AWG1.Columns[ i ].Title := q1.fields[ i ].fieldname; AWG1.Columns[ i ].AllowSizing := false;
Strange isn't it.
(NB! Forum issue: writing a text containing [ i ], as in the above columns[ i ], I have to add a space on both sides of the "i" between the brackets. If not, the brackets and the "i" is removed and AWG1.Columns[ i ].AllowSizing := false; becomes AWG1.Columns.AllowSizing := false;
Hi Bart, i'll remember to uncheck the BBCodes option. Thanks.
Another strange forum issue just came up: As you answered my previous post, I received a notofication for your answer by email 5 times. But with your reply to my other topic, I only received 1 email, so it's not a general behavior.