DEMONSTRATION ON LIST BOXES


9.      DEMONSTRATION ON LIST BOXES

DEMONSTRATION ON LIST BOXES
Step 1:-Select a NEW file.
Step 2:-Select a project tab from new window and from that select MFC application wizard [exe] option and give a project name as list box and click ok.
Step 3:-
Þ    MFC Application Wizard window is appeared.
Þ    Select dialog based default settings in step 1, click next.
Þ    Select default settings from step2 to step6 and click finish.
Þ    New projects information on window will appear and click ok.
Step 4:-Drag and following controls on to the dialog box a list box, edit box, and two static text, the static text box used to display the text.
Step 5:-Add a member variable to the list box, for that class wizard-> member variable tab-> IDC_LIST1-> click on add variable-> connect the member variable m_list to the list box, and make sure that you select control in the category box and add variable m_text to IDC_EDIT1 click ok.
Step 6:-To initialize data in dialog box we add code to OnInitDialog() method. So under class view click on CListboxDlg, in that select OnInitDialog() method and add the following code.
                        BOOL CListboxDlg::OnInitDialog()
                        {
                                    CDialog::OnInitDialog();
                                    m_list.Addstring (“Item 1”);
                                    m_list.Addstring(“Item 2”);
                                    m_list.Addstring(“Item 3”);
                                    m_list.Addstring(“Item 4”);
                                    m_list.Addstring(“Item 5”);
                                    m_list.Addstring(“Item 10”);
                        }

Step 7:-To handle the list box, connect a member variable m_text to the text in the text box and class wizard->message maps->IDC_LIST1->double click on LBN_DBCLK in the message box-> OnDblClkList1()-> click ok.
                        void CListboxDlg::OnDblclkList1()
                        {
                                    m_list.GetText(m_list.GetCursel(),m_text);
                                    UpdateData(false);
                        }

Step 8:-Build………….Compile…………Execute.

No comments:

Post a Comment