http://www.codeproject.com/KB/miscctrl/gridctrl.aspx
when I run the dialog box as a modal dialog box everything works well,
but when I created the modeless version of it, the custom grid didn't
respond correctly. To create the modeless version I first created an
array of the dialog class in the header file.
CGridHolderDLG *gridArray[50];
and in a function that I create the dialog I do this:
void showGrid(char *header,
long numberOfRows,
long numberOfColumns,
char **columns,
char **columnLabels,
long columnSortFlags[],
SdaiPrimitiveType columnPrimtypes[],
SdaiServerContext serverContextId)
{
// need for exporting this function
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// create a dialog box and fill it
numberOfGrids++;
// CGridHolderDLG myGrid;
/* myGrid.setHeader(header);
myGrid.setNumberOfRows(numberOfRows);
myGrid.setNumberofColumns(numberOfColumns);
myGrid.setColumns(columns);
myGrid.setColumnLables(columnLabels);
myGrid.setColumnSortFlags(columnSortFlags);
myGrid.setColumnPrimitypes(columnPrimtypes);
myGrid.setServerContext(serverContextId);
myGrid.setArrayNum(numberOfGrids);
*/
gridArray[numberOfGrids] = new CGridHolderDLG();
gridArray[numberOfGrids]->setHeader(header);
gridArray[numberOfGrids]->setNumberOfRows(numberOfRows);
gridArray[numberOfGrids]->setNumberofColumns(numberOfColumns);
gridArray[numberOfGrids]->setColumns(columns);
gridArray[numberOfGrids]->setColumnLables(columnLabels);
gridArray[numberOfGrids]->setColumnSortFlags(columnSortFlags);
gridArray[numberOfGrids]->setColumnPrimitypes(columnPrimtypes);
gridArray[numberOfGrids]->setServerContext(serverContextId);
gridArray[numberOfGrids]->setArrayNum(numberOfGrids);
// myGrid.DoModal();
gridArray[numberOfGrids]->Create(IDD_GRIDDIALOG);
gridArray[numberOfGrids]->ShowWindow(TRUE);
}
this is an exported function that is used to create the dialog box
from a C environment. the problem is that in this method
typedef void(*FnPtrT)(char*);
void CGridHolderDLG::OnGridDblClick(NMHDR *pNotifyStruct, LRESULT* /
*pResult*/)
{
NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
// Can we do it?
if (!IsValid(pItem->iRow, pItem->iColumn))
return;
if (pItem->iRow != 0 && (myColumnPrimitypes[pItem->iColumn - 1] ==
sdaiINSTANCE || myColumnPrimitypes[pItem->iColumn - 1] == sdaiAGGR)) {
CGridCellBase* pCell = m_Grid.GetCell(pItem->iRow, pItem-
>iColumn);
if (pCell) { // if cell exist check for column type
if (myColumnPrimitypes[pItem->iColumn - 1] == sdaiINSTANCE)
{ //if instance call showInstanceCallFromGridDLL()
FnPtrT FnPtr = (FnPtrT)::GetProcAddress(GetModuleHandle
(NULL), "showInstanceCallFromGridDLL");
if(FnPtr)
(*FnPtr)((char *)pCell->GetText());
} else if (myColumnPrimitypes[pItem->iColumn - 1] ==
sdaiAGGR) { //if aggragate call showInstanceCallFromGridDLL()
FnPtrT FnPtr = (FnPtrT)::GetProcAddress(GetModuleHandle
(NULL), "showAggrCallFromGridDLL");
if(FnPtr)
(*FnPtr)((char *)pCell->GetText());
}
}
}
}
which calls a function outside of the the DLL, the
if (pItem->iRow != 0 && (myColumnPrimitypes[pItem->iColumn - 1] ==
sdaiINSTANCE || myColumnPrimitypes[pItem->iColumn - 1] == sdaiAGGR))
{
statement does not work, the second part is always false. and the
settings for the actual grid changes in the modeless version. e.g. all
cell become editable.
is there some kind of a setting one should do when working with custom
controls and modeless dialog boxes? or is the array doing something
that it shouldn't do.
thanks
ehsan
Also I'm assuming that the setXXXX methods that you are calling before the
create is called in ShowGrid, don't actually manipulate any controls on the
dialog, and simply just store information.
Anyway, if you give more details on how your program is laid out then maybe
we can recreate your problem and give a solution.
AliR.
"bachegool" <esade...@gmail.com> wrote in message
news:e2d57d69-4f76-41c8...@h30g2000vbr.googlegroups.com...
The code in the mail is the DLL. The showGrid is the exported
function, I did this to avoid changing the Grid library that I am
using and it's much easier. the setXXX belong to the dialog that holds
the grid. The problem is that for some reason my private variables are
being rewritten after the grid is displayed. so when I use gridArray
[numberOfGrids]->setColumnPrimitypes(columnPrimtypes); the
"columnPrimtypes" and "myColumnPrimitypes" are correct, but after this
when I'm using the grid it is written over.
ehsna
Don't use these sort of controls in Production environment (not
professional and bugged)
Use one of the native Win32 Grid controls.