Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Can I place ComboboxBar and ToolBar both side by side on the propertyGrid Collapse All
Subject Author Date
Nitesh Singh Nov 6, 2006 - 2:03 AM

Hi Support....

With the default implementation of the property grid control, the comboboxbar is on the top and after that propertygridtoolbar. I want both to be aligned in the same row. ( e.g.... a combobox, then the toolbar with buttons... ......... or first the propertyGridtoolbar buttons and then combo box in the same line)............

Please tell me.... what are the overrides that I have to do or change the code.. Please tell me in details.. thanks alot. :)

Nitesh Singh Nov 6, 2006 - 2:07 AM

actually I don’t have many buttons on the toolbar (only 4) and also the text displayed in the combobox is not big.. so it will look alot better if both are packed in the same row.. thank you..

Technical Support Nov 7, 2006 - 4:48 AM

You could create the combo box as a button in the toolbar. Override the CExtPropertyGridCtrl::OnPgcCreateBars() virtual method and make it the same as the original method except you should create the CExtPropertyGridComboBoxBar window as a child of CExtPropertyGridToolBar (not as a child of CExtPropertyGridCtrl ) and attach the combo box to a newly added toolbar button. The CExtPropertyGridComboBoxBar::CExtPropertyGridComboBoxBar() constructor allows you to specify a pointer to a CExtPropertyGridCtrl window and, as a result, you can create the combo box anywhere even outside the property grid control.

Suhai Gyorgy Nov 8, 2006 - 2:15 AM

I tried to make this work as you suggested, but the solution doesn’t seem to be good. The main problem is the parent of the combobox. If I make it to be the ToolBar, as you said above, the propertygrid’s GetChildByRTC method will return NULL for the combobox, as the grid doesn’t have a combobox child. If the combobox’s parent is the grid, then toolbar’s SetButtonCtrl will give an assertion as the button-control has to be the toolbar’s child.

Nitesh Singh Nov 9, 2006 - 12:02 AM

when I followed the 1st method i.e. in OnInitDialog then when I was calling combobox to populate for property values..
    
CExtPropertyGridComboBoxBar * pCombo = STATIC_DOWNCAST(    CExtPropertyGridComboBoxBar, m_PGC.GetChildByRTC(RUNTIME_CLASS(CExtPropertyGridComboBoxBar)));
    ASSERT_VALID( pCombo );


pCombo is NULL and is giving assertion...

and when I did by second method i.e. OnPgcCreateBars() then it was giving assertion even before the stated line.

Nitesh Singh Nov 7, 2006 - 11:23 PM

Thank u sir.. One request.. can u do it in an example... as I fear to change the code.

Technical Support Nov 8, 2006 - 9:32 AM

To put the combo box into the toolbar, you can simply use the following code at the end of the CMainDlg::OnInitDialog() method in the CompoundProperties sample:

CWnd * pComboBox = m_PGC.GetChildByRTC( RUNTIME_CLASS( CExtPropertyGridComboBoxBar ) );
CWnd * pToolBar = m_PGC.GetChildByRTC( RUNTIME_CLASS( CExtPropertyGridToolBar ) );
pComboBox->SetParent( pToolBar );
CRect rc;
pComboBox->GetWindowRect( &rc );
pToolBar->ScreenToClient( &rc );
rc.InflateRect( -50, -3, -5, -3 );
pComboBox->MoveWindow( &rc );
m_PGC.RecalcLayout();
You can also use this class that does the same:
class CMyPropertyGridCtrl : public CExtPropertyGridCtrl
{
public:
    bool OnPgcCreateBars()
    {
        if( ! CExtPropertyGridCtrl::OnPgcCreateBars() )
            return false;
        CWnd * pComboBox = GetChildByRTC( RUNTIME_CLASS( CExtPropertyGridComboBoxBar ) );
        CWnd * pToolBar = GetChildByRTC( RUNTIME_CLASS( CExtPropertyGridToolBar ) );
        pComboBox->SetParent( pToolBar );
        CRect rc;
        pComboBox->GetWindowRect( &rc );
        pToolBar->ScreenToClient( &rc );
        rc.InflateRect( -50, -3, -5, -3 );
        pComboBox->MoveWindow( &rc );
        RecalcLayout();
        return true;
    }
};

Nitesh Singh Nov 8, 2006 - 11:09 PM

it was giving me an assertion faliure.. I followed the second method.. As I have two extra buttons on toolbar.. tell me.. what to do. thanks.

Nitesh Singh Nov 8, 2006 - 11:15 PM


bool CMyPropertyGridCtrl::OnPgcCreateBars()
{
    if( ! CExtPropertyGridCtrl::OnPgcCreateBars() )
return false;
CExtPropertyGridToolBar * pWnd =
STATIC_DOWNCAST(
CExtPropertyGridToolBar,
GetChildByRTC(RUNTIME_CLASS(CExtPropertyGridToolBar))
);
if( pWnd == NULL )
return false;
    
pWnd->InsertButton();// -1, ID_SEPARATOR );
// pWnd->InsertButton( -1, IDC_EDI );
pWnd->InsertButton( -1, 1);
// pWnd->InsertButton( -1, ID_SEPARATOR );

UINT nCmdID = IDI_SELECTION_MODE0;
    UINT nIconID;

CExtCmdItem cmd;
cmd.m_nCmdID = nCmdID;
    int mode = ((CMyApp*)AfxGetApp())->m_Mode;
    if( mode == 0)
    {
        nIconID = IDI_SELECTION_MODE0;
        cmd.m_sTipStatus = _T("Toggle selection mode");
        cmd.m_sTipTool = _T("Toggle to 1");
    }
    else
    {
        nIconID = IDI_SELECTION_MODE1;
        cmd.m_sTipStatus = _T("Toggle selection mode");
        cmd.m_sTipTool = _T("Toggle to 0");
    }

VERIFY(g_CmdManager->CmdSetup(g_CmdManager->ProfileNameFromWnd(pWnd->GetSafeHwnd()), cmd, true, NULL));
HICON hIcon =(HICON)::LoadImage(((CMyApp*)AfxGetApp())->m_hRes, MAKEINTRESOURCE( nIconID ), IMAGE_ICON, 16, 16, 0);
if( hIcon != NULL )
{
VERIFY(g_CmdManager->CmdSetIcon(g_CmdManager->ProfileNameFromWnd(pWnd->GetSafeHwnd()), nCmdID, hIcon, false));
}
pWnd->InsertButton();
pWnd->InsertButton( -1, nCmdID );

// CExtCmdItem cmd;
    nCmdID = nIconID = IDI_SELECT_OBJECT;
cmd.m_nCmdID = nCmdID;
    
    cmd.m_sTipStatus = _T("Select objects");
    cmd.m_sTipTool = _T("Select objects");

VERIFY(g_CmdManager->CmdSetup(g_CmdManager->ProfileNameFromWnd(pWnd->GetSafeHwnd()), cmd, true, NULL));
hIcon =(HICON)::LoadImage(((CMyApp*)AfxGetApp())->m_hRes, MAKEINTRESOURCE( nIconID ), IMAGE_ICON, 16, 16, 0);
if( hIcon != NULL )
{
VERIFY(g_CmdManager->CmdSetIcon(g_CmdManager->ProfileNameFromWnd(pWnd->GetSafeHwnd()), nCmdID, hIcon, false));
}
pWnd->InsertButton( -1, nCmdID );

//extra coding as suggested.....
CWnd * pComboBox = GetChildByRTC( RUNTIME_CLASS( CExtPropertyGridComboBoxBar ) );
CWnd * pToolBar = GetChildByRTC( RUNTIME_CLASS( CExtPropertyGridToolBar ) );
pComboBox->SetParent( pToolBar );
CRect rc;
pComboBox->GetWindowRect( &rc );
pToolBar->ScreenToClient( &rc );
rc.InflateRect( -50, -3, -5, -3 );
pComboBox->MoveWindow( &rc );
RecalcLayout();

return true;
}

Technical Support Nov 9, 2006 - 11:21 AM

You should replace -50 in the line below with a greater value which is more acceptable for your property grid’s toolbar having four buttons:

rc.InflateRect( -50, -3, -5, -3 );


Nitesh Singh Nov 10, 2006 - 2:31 AM

1st thing I want to say that... the second method i.e. is bool OnPgcCreateBars() no way working for me.. (main as well as the test project). Second if I put the code given by u CMainDlg::OnInitDialog() then... it is working until I don’t call the comboboxbar again..

but I need to call that again and again.(so that I can refresh my property grid whenever a new object is selected.). and when I am using m_PGC.getchildbyRTC() for combobox.. it is returning NULL. and giving assertion. SO please tell me the alternate method to get the comboboxbar....... I cudn’t find any function like getchild in Toolbar class please help....

I have attached a sample project in the mail...

http://www.filefactory.com/file/fe0424/
The file is here too...

Nitesh Singh Nov 10, 2006 - 3:34 AM

I have donw one work around....

In my dialog class I am having a pointer....
CExtPropertyGridComboBoxBar* m_pComboTemp;

and assigning this pointer to the combobox pointer in OnInitDialog....


Now where ever I want to access the comboboxbar.. I am just taking m_pComboTemp... This is working for me for now. But I don’t know if I have created one more bug while doing so. So if there is a better method please do tell me.

Nitesh Singh Nov 10, 2006 - 5:19 AM

now the next problem is that..

I have put my dialogbox on a control bar so that I get the docking and resizing.. I want the combobox to occupy rest of the area of the toolbar as the dialog box is resized. how to do that....

Technical Support Nov 10, 2006 - 12:10 PM

You can adjust the combo box’s size when the control bar is resized in this way:

class CYourBar : public CExtControlBar
{
protected:
    virtual LRESULT WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
    {
        LRESULT lResult = CExtControlBar::WindowProc( message, wParam, lParam );
        if( message == WM_SIZE )
        {
            CExtProperyGridCtrl * pPGC = DYNAMIC_DOWNCAST( CExtProperyGridCtrl, GetWindow( GW_CHILD ) );
            if( pPGC )
            {
                // PUT YOUR COMBO BOX POSITION ADJUSTMENT CODE HERE
            }
        }
        return lResult;
    }
};
The adjustment code should be similar to that you are already using. But the right side of the combo box window should adjusted according to the size of the parent toolbar window.

Nitesh Singh Nov 10, 2006 - 10:27 PM

I think I am making some silly mistake. I just copied the code u provided for resizing didn’t add any thing. But it is giving me complile error.I have mailed you my sample project.

Problem with me is that I am not using CExtControlBar. I have mentioned about this earlier also. that since your CExtControlBar is incompatible with MFC Controlbar and Toolbar. And I can not switch from MFC toolbar and Controlbar which are already there. So I am having an alternative Controlbar.

please make the changed so that I can get the resizing comboboxbar... thanks alot.

Nitesh Singh Nov 13, 2006 - 10:37 PM

http://www.filefactory.com/file/883dab/

I have uploaded the test project here also. And mailed u as well. Please give one solution. thanks.. Reply as soon as possible..

Technical Support Nov 15, 2006 - 12:54 PM

We downloaded your project and fixed all the problems in it. Please check your e-mail.

Nitesh Singh Nov 16, 2006 - 9:06 PM

Thanks a lot for the support... :)