Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Generating tables in a visual c++ window


i am trying to generate a table in an application made in visual c++. I already tried the MFC at MSDN and cant come along with it really.

Maybe someone could give me an example how to build an 2x3 table, without opening 6 boxes- i need to do it with one.

Any suggestions?


1 Solution
A table of what?
Maybe all you need is one grid

Use a List Control.  Set the view mode to Report.

This will give you a multi-column, multi-row table with just about everything built in.
most probably...
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

ZazenAuthor Commented:
I wanted to use a list control. Neither my teacher nor any of the books i have can explain to me how to format it. Any suggestions?
I also had the idea of using a multilined text control. But i cant access the second and following lines of text. Any idea of this?
Then i read about adding excel tables, but thats far beyond my knowledge of visual c++ (for now...)

The table should look something like that:

x       y  (I wanted to use CHeaderCtrl on this, but     dont know ho too)
0       10
10      20

Any new ideas?
If you insert a CListCtrl, go to the properties and change the "View" property to "Report" to use the CHeaderCtrl (as imadjinn suggested).  Then you call "InsertColumn" to insert each of your columns.  Then call InsertItem to insert the item, and SetItemText to set the text of a field.  Like if I wanted to insert two columns into a list control named m_list, it might look like:
CRect rect;
m_list.GetWindowRect(rect); // Get the list control's size so that you can make the columns the same size
// Leave a couple of pixels for the separator, which is why the "- 2" is added
m_list.InsertColumn(0, "x", LVCFMT_LEFT, rect.Width() / 2 - 2); // Insert the first column
m_list.InsertColumn(1, "y", LVCFMT_LEFT, rect.Width() / 2 - 2); // Insert the second column
m_list.InsertItem(0, "0"); // Insert the first item
m_list.SetItemText(0, 1, "10"); // Set the second column's value in the first item
m_list.InsertItem(1, "10");
m_list.SetItemText(1, 1, "20");
this is a simple enough table to also maybe just output the text to the window directly (to the DC)

ZazenAuthor Commented:
Thank you mnashadka, dont have the time yet, but will try it tomorrow morning- hope i get it...

And thank you Dancer, but i tried that. I picked multiline in the output control, but i cant insert the second line, cause it overwrites the first. Suggestions?

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now