koushal.vv 0 Light Poster

Hi,


i am using CMsFlexGrid in my project.
the problem i m facing is the alignment of data
ie when i store integer, double its getting aligned to right
when i store strings its getting left aligned pls help.
Display look very horrible :( .how to change it i dont even have tat class in MSDN.

Dani AI

Generated

— many grid controls (including the classic FlexGrid family) will automatically align numeric VARIANTs to the right and text to the left. That behaviour is a display convenience, not a bug. To make the display consistent you must set alignment explicitly (per cell or per column) or draw the cell contents yourself.

How to fix it (practical checklist)

  • Inspect the MFC wrapper generated by "Add Class from ActiveX Control" for your CMSFlexGrid. The generated .h/.cpp shows which alignment/setter methods or enums the control exposes; call the appropriate property on the grid (per-column or per-cell) after you create/populate it.
  • If the wrapper does not expose an alignment API, either subclass/owner-draw the control and draw text with DrawText flags (DT_RIGHT, DT_LEFT, DT_CENTER), or convert values to formatted strings before writing them to cells (note: converting numbers to strings changes sorting/typing behavior).

Owner-draw example (MFC)
This is a minimal drawing approach you can reuse inside your cell-draw handler or custom paint routine:

CString text = _T("12345");      // cell text you want right-aligned
CRect   rcCell = /* cell rectangle */;
CDC*    pDC = /* device context for cell */;
pDC->DrawText(text, &rcCell, DT_SINGLELINE | DT_VCENTER | DT_RIGHT);

Notes and cautions

  • Converting numeric data to strings for alignment will break numeric sorting and any numeric arithmetic done using the grid’s stored values.
  • If you can, set alignment once (per column) immediately after creating the columns. That keeps the code simple and avoids cell-by-cell fixes.
  • If API names are unclear, paste the generated wrapper header into a search to find alignment-related enums or methods; share that header if you need more precise code.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.