|
I have merged following cells:
m_iCols = 20;
m_Grid.MergeCells(0,2,0,m_iCols-1); // 0 row
m_Grid.MergeCells(2,0,2,1); // 2 row
m_Grid.MergeCells(0,0,0,1); // 0th row
m_Grid.MergeCells(1,0,1,1); //1 row
I am using MFC grid control 2.27.
I have 20 rows and 20 columns. 4 rows are fixed row and 1 columns is fixed.
The grid visible portion has 10 rows and 6 columns. After 5th column we can view columns by scrolling. There is no problem until the grid is scrolled. But when we edit column 6 onwards and click on anywhere in grid, merged cells' text is hidden. Border of cell is not visible for merged cell and in header cell (0, 0) copies the text of cell (0, 2) cell.
|
|
|
|
|
Hi,
I was using the grid control with merge cell function in dialog model,Find the grid line will disappear if set a lot of continuously cell bkground by SetItemBkColour function.
But it's ok in document model,Who can help me or please fix the bug.
Thanks
|
|
|
|
|
Merged cell disapear if the cell's column is clicked.
|
|
|
|
|
Hello,
I am pretty new to this technology. Let me know if i can generate an OCX and DLL for this object?
thanks.
|
|
|
|
|
|
Hi i am unable to download the attachment file.
Nice talking to you. If you judge people, you have no time to love them. -- Mother Teresa
|
|
|
|
|
the last row printed out is actually not underlined ,what is wrong?
thank you
zhouhao from zju
|
|
|
|
|
when merging cells in virtual mode, it doesn't display properly.
if any one would help me to fix it, i will be appreciated
very much
|
|
|
|
|
I have a BIG problem since using the merged control. The CGridCellBase::PrintCell is a bit stuffed up for two fundamental reasons and I don't have the answer.
Firstly, there is a call at the start to pDC->Rectangle(rect) and this basically means avery cell gets all of the lines drawn! It is not obeying the users choices. The OnPrint function handles drawing the lines.
Also, it has some code remmed out and indicates it as disabled and this means my font colours are not showing.
How can I fix these two problems?
Thank you.
Andrew
|
|
|
|
|
OK, I had a look at an older set of data files I have for the grid control and I noticed the PrintCell worked a little differently:
else
crFG = (GetBackClr() != CLR_DEFAULT ||
(GetTextClr() != CLR_DEFAULT && GetTextClr() != pDefaultCell->GetTextClr())) ?
GetTextClr() : RGB(0, 0, 0);
This fixes my font colours. Now my print preview behaves for font colours.
As for the grid lines being drawn, I did this:
rect.InflateRect(1,1);
rect.DeflateRect(1,1);
This sorts me out. If I was using merged cells then I think I would have a problem here, but I don't. The thing is, it is the GRID that draws the cells grid lines in OnPrint just after the PrintCell call. Thus the ->Rectangle call should NOT be done in PrintCell. If anything, OnPrint should be adjusted just after the PrintCell call to allow for merged cells and thus print the boundary of the merged cell based on the GridLines parameters. I am not brave enough to do this.
Andy
|
|
|
|
|
Thx for your great work~
I want to save the infomation of merged grid in database,for showing the grid in next time,thank U!
leon
|
|
|
|
|
Thx for your great work~
I want to add a bitmap file on a merged cell... or just on a cell....
Is there any way to do that????
|
|
|
|
|
I have it working by copying in the 4 files (which are v2.24) into the 2.26 code. however, there are problems (such as grid lines not showing up on colored backgrounds). There were several things changed from 224 to 226, but I do not have the older sources, so I can not tell what was changed.
If someone has the original 2.24 source files (prior to the Mergecell changes), That would also work, as a set of diff files can be created, to obtain JUST the modifications needed by the Mergecell functions.
TIA, Jim.
|
|
|
|
|
|
I complete this.
compare file with the UltraEdit's
then modify the file of 2.26 version
It compile successful and run successful
If you want to get the code, Then Mail Me,please;
My Mail is geoh#vip.qq.com (replace # to @)
the mail's subject must be MFC Grid Control with Merge!
Thanks,My English is bad,Sorry
|
|
|
|
|
when merge cells in which some are already merged, the result is wrong. To fix this bug,you have to adjust the merged range to the actual range.
here is my solution:
<br />
void CGridCtrl::MergeCells(int nStartRow, int nStartCol, int nEndRow, int nEndCol)<br />
{<br />
int nMinRow= nStartRow,nMaxRow= nEndRow,nMinCol= nStartCol,nMaxCol= nEndCol;<br />
for (int row1=nStartRow;row1<=nEndRow;row1++) <br />
{<br />
for (int col1=nStartCol;col1<=nEndCol;col1++) <br />
{<br />
CGridCellBase *pCell= (CGridCellBase*)GetCell(row1,col1);<br />
ASSERT(pCell);<br />
if (pCell->IsMerged()) {<br />
CCellRange range=pCell->GetMergeRange();<br />
nMinRow = min(nMinRow,range.GetMinRow());<br />
nMinCol = min(nMinCol,range.GetMinCol());<br />
nMaxRow = max(nMaxRow,range.GetMaxRow());<br />
nMaxCol = max(nMaxCol,range.GetMaxCol());<br />
}<br />
}<br />
}<br />
<br />
nStartRow = nMinRow;<br />
nEndRow = nMaxRow;<br />
nStartCol = nMinCol;<br />
nEndCol = nMaxCol;<br />
<br />
for(int row=nStartRow;row<=nEndRow;row++) <br />
}<br />
----
You have nothing to lost, but everything to gain.
http://www.ucosoft.com
|
|
|
|
|
could you send me the MergeCells functions?
i added your code to my solution,but it doesn't work.
could you give me some suggestions?
Thanks a lot !
|
|
|
|
|
I can delete rows grom the grid , even when there are merged rows.
but, if my very last row is merged, it crashes.
|
|
|
|
|
Surely this code is wrong?
void CGridCellBase::operator=( CGridCellBase& cell)<br />
{<br />
if (this == &cell) return;<br />
<br />
SetGrid(cell.GetGrid());
<br />
SetText(cell.GetText());<br />
SetImage(cell.GetImage());<br />
SetData(cell.GetData());<br />
SetState(cell.GetState());<br />
SetFormat(cell.GetFormat());<br />
SetTextClr(cell.GetTextClr());<br />
SetBackClr(cell.GetBackClr());<br />
SetFont(cell.IsDefaultFont()? NULL : cell.GetFont());<br />
SetMargin(cell.GetMargin());<br />
SetMergeCellID(cell.GetMergeCellID());<br />
SetMergeRange(cell.GetMergeRange());<br />
Show(cell.IsShow());<br />
}
When you look at SetMergeRange:
void CGridCellBase::SetMergeRange(CCellRange range)<br />
{<br />
m_MergeRange=range;<br />
m_bBaseForMerged = 1;<br />
}<br />
It always sets the cell as a merged base cell. But what if it not actually a merged cell in the first place that you are copying or doing stuff with? I wonder if this is the cause of my crashes.
I would have thought that it should be passing in the state of the cell.XXXXX merging properties.
Can some one help me here?
|
|
|
|
|
The bug sniffer has been at work. Do this to avoid the problems:
Step 1:
In CGridCellBase operator= change:
SetMergeRange(cell.GetMergeRange());
to
SetMergeRange(cell.GetMergeRange());
m_bBaseForMerged = cell.IsBaseForMerged();
The bug in SetMergeRange is here:
void CGridCellBase::SetMergeRange(CCellRange range)<br />
{<br />
m_MergeRange=range;<br />
--> m_bBaseForMerged = 1; <---<br />
}
It should not do that. It should be using the value of the cell being copied. Only true merged cells should have a base flag set.
Step 2:
In CGridCellBase InflateMergedRange change to:
void CGridCellBase::InflateMergedRange(int cx, int cy)
{
if (IsMerged())
{
m_MergeRange.Set(
m_MergeRange.GetMinRow() + cy,
m_MergeRange.GetMinCol() + cx,
m_MergeRange.GetMaxRow() + cy,
m_MergeRange.GetMaxCol() + cx
);
}
else if(IsMergeWithOthers())
{
m_MergeCellID.row += cy;
m_MergeCellID.col += cx;
}
}
The bug is that only the BASE base has a valid range object.
Likewise, only merged cells utilise a merged cell id object.
The merged cell id object was not getting updated, so the merged cells now pointed to the wrong master base cell.
Because we have now corrected the operator= call in step 1, we could use IsBaseForMerge instead of IsMerged. But this works using the existing method IsMerged.
Step 3:
In CGridCtrl::InflateMergedRanges change to:
void CGridCtrl::InflateMergedRanges(int nStartRow, int nStartCol, int cx, int cy)
{
for(int i = nStartRow; i < GetRowCount(); i++)
{
for(int j = nStartCol; j < GetColumnCount(); j++)
{
if(GetCell(i, j)->IsMerged() || GetCell(i, j)->IsMergeWithOthers())
{
GetCell(i, j)->InflateMergedRange(cx, cy);
}
}
}
}
As described for step 2, you need to intercept and modify both base cell (with a merge range) and merged cells (with a merged cell id).
|
|
|
|
|
When you autosize a column, and the cell is merged and the master cell, the column ends up being resized and the grid can effectively double in width.
I did this to overcome the problem:
AutoSizeColumn:
for (int nRow = nStartRow; nRow <= nEndRow; nRow++)<br />
{<br />
CGridCellBase* pCell = GetCell(nRow, nCol);<br />
if (pCell && !pCell->IsMerged())<br />
{<br />
size = pCell->GetCellExtent(pDC);<br />
<br />
if (size.cx > nWidth)<br />
nWidth = size.cx;<br />
}<br />
}<br />
|
|
|
|
|
I have some problems here. Can anyone help me solve them?
1. In order to set a merged set of cells as the focus cell, you must click on the "base" cell for the merged cells. You can't click on any of them.
2. Related to this (perhaps). My grid uses combo cells and the odd row of merged text cells. If I am on a combo cell and the move down a row using the cursor key, it renders the dropdown arrow of the hidden combo cell. This would explain why item 1 above does not let you click a none-based merged cell.
The question is how can I solve these two problems? It would be nice to click on any merged cell and it set the focus correctly and it would be nice when moving up/down etc. that it set the focus cell correctly.
Andrew
|
|
|
|
|
What you have to do is not let the grid set focus to a cell that is merged with others. Add this code to SetFocusCell:
if (cell.row != -1 && cell.row < GetFixedRowCount())<br />
cell.row = GetFixedRowCount();<br />
if (cell.col != -1 && cell.col < GetFixedColumnCount())<br />
cell.col = GetFixedColumnCount();<br />
<br />
*** NEW CODE ***<br />
CGridCellBase *pCell = NULL;<br />
pCell = GetCell(cell);<br />
if(pCell != NULL && pCell->IsMergeWithOthers())<br />
cell = pCell->GetMergeCellID();<br />
Now, it will select the right cell and this works for mouse and cursor movements. It also avoids the rendering of grid lines.
|
|
|
|
|
Do you have the CGridCtrl with MergeCell function ?
|
|
|
|
|
Can't the same instructions be followed in 2.25?
Andrew
|
|
|
|
|