-
StringGrid,Memo
Goodmorning
I want some help. I have a stringgrid with some values inside.
1 8,2
2 8,3
3 8,7
4 10,1
So my question is how i can take these fields to a memo component...any ideas;;;;; is it simple;;;;;; because i want to print it after...can i print it straight from the stringgrid my values to a printer
-
Re: StringGrid,Memo
Yes you can do that using similar code to this -
Code:
int k=0;
for (int rowint=0;rowint<StringGrid1->RowCount;rowint++)
{
for (int colint=0;colint<StringGrid1->ColCount ;colint++)
{
Memo1->Lines->Strings[k++] = StringGrid1->Cells[rowint][colint];
}
}
or, as you have mentioned that you will print the stringgrid values lateron,
you can use - TextOut() or Drawtext to print on a TPrinter->Canvas.
Suppose your StringGrid has 3 column, px[0], px[1] and px[2] are 3 values to determine x position of printer output, py0 is top position, py is y position and stepy is line distance:
Code:
for(int i=0;i<StringGrid1->RowCount;i++)
{
py=py0 + i*stepy;
for(int j=0;j<=3;j++)
{
Printer()->Canvas->TextOut(px[j],py,StringGrid1->Cells[j][i]);
}
I am not a hard core fan of StringGrid, but have a good intension to help you out.
Hope this helps.
-
Re: StringGrid,Memo
Hi
you help little and thank you but still some little problems
for this:
int k=0;
for (int rowint=0;rowint<StringGrid1->RowCount;rowint++)
{
for (int colint=0;colint<StringGrid1->ColCount ;colint++)
{
Memo1->Lines->Strings[k++] = StringGrid1->Cells[rowint][colint];
}
}
I took only the first column and not the second. So need to fix the code little more
Code:
for(int i=0;i<StringGrid1->RowCount;i++)
{
py=py0 + i*stepy;
for(int j=0;j<=3;j++)
{
Printer()->Canvas->TextOut(px[j],py,StringGrid1->Cells[j][i]);
}
for that i have only 2 dimensions so we can fix it more simple.. any ideas
-
Re: StringGrid,Memo
It was just an example, you could have modified it according to your need;
anyway, I have deleted some part of code to deal with the exact requirement you have here -
"I took only the first column and not the second. So need to fix the code little more"
So, the first one would be like this -
Code:
for (int rowint=0;rowint<StringGrid1->RowCount;rowint++)
{
//as you want only first column, I have hardcoded the Cells values to consider only [0] th/1st column.
Memo1->Lines->Strings[rowint] = StringGrid1->Cells[rowint][0];
}
"for that i have only 2 dimensions so we can fix it more simple.. any ideas"
So, the second one would be like this -
Code:
for(int i=0;i<StringGrid1->RowCount;i++)
{
py=py0 + i*stepy;
//two columns - 0,1; so loop will go from j-0 to j<2
for(int j=0;j<2;j++)
{
Printer()->Canvas->TextOut(px[j],py,StringGrid1->Cells[j][i]);
}
}
Hope this time you will understand it more clearly.
"Please put tags around your code to preserve indentation and make it more readable."