In Feburary 2016 19,
Create a new project in Visual Studio to manipulate the control. From the upper menu bar, click 'File' > 'New' and select 'MFC AppWizard(exe)' in the 'Projects' tab. Enter a name for the project in the 'Project name' text box and click 'OK.' Select the 'Dialog based' radio button and click 'Finish' and then 'OK.' A dialog screen with two control buttons, one 'OK' and one 'Cancel,' is displayed in the Design View mode.
Add MFC controls on the dialog screen: one list box and some auxiliary controls to make the tutorial more interesting. To find a list box, move the mouse over the controls toolbox and read the popup balloons. Click the 'List Box' icon and click on the dialog screen to add it there. In a similar fashion add an 'Edit Box' and two 'Buttons.'
Modify the MFC controls. Right-click on the list box, select 'Properties' and change the ID to IDC_MYLISTBOX, under the 'General' tab. Do the same to the edit box and change its ID to IDC_MYEDITBOX. In one button, change the ID to IDC_MYBUTTONADD and the Caption to 'Add.' In the other button, change the ID and Caption to IDC_MYBUTTONREM and 'Remove,' respectively.
Join the list box and edit box using the Class Wizard. From the upper menu, click 'View' > 'Classwizard' or press Ctrl+W. Select 'IDC_MYLISTBOX' under the 'Member Variables' tab and click 'Add Variable.' Type 'm_myListBox' in the 'Member variable name' text box and select 'Control' under 'Category.' Click 'OK.' Next, select 'IDC_MYEDITBOX,' click 'Add Variable' and give the name 'm_myEditBox.' Don't change the combo boxes. Click 'OK' to close the class wizard.
Give some functionality to the Add button. Double-click the 'Add' button. When the 'Add Member Function' window appears, click 'OK.' Copy and paste the following code inside the '::OnMybuttonadd()' function, under the comment:
CString str;
UpdateData();
str = m_myEditBox;
UpdateData(FALSE);
m_myListBox.AddString(str);
Repeat Step 5 for the 'Remove' button. Copy and paste the following code inside the '::OnMybuttonrem()' function, under the comment:
int pos;
CString str;
pos = m_myListBox.GetCurSel();
m_myListBox.DeleteString(pos);
Compile and run the code. Type some text in the edit box and click the Add button. That text will be added as a row in the list box. Next, highlight a list box row and click Remove. This action deletes the row.
In Feburary 2016 19,
Showing posts with label toolbox. Show all posts
Showing posts with label toolbox. Show all posts
Friday, 19 February 2016
Friday, 5 February 2016
How to Add Columns to GridViewIn Feburary 2016 05,
In Feburary 2016 05,
Open Visual Studio. Click 'File' and select 'New Website.'
Click 'Visual C#,' and then double-click 'ASP.NET Website' to create a new website. The markup code for the default Web page appears in the center of the Visual Studio window.
Click the 'Design' button at the bottom of the window to view the form designer.
Click 'File' and select 'Toolbox.' Visual Studio will display the toolbox.
Scroll down and locate the 'GridView' control. Double-click that control to place it on the form.
Press 'F7.' The source code window will open and display this code:protected void Page_Load(object sender, EventArgs e){}This is the page load method. It runs when the Web page loads in a browser. Note the two bracket symbols below the first line of code.
Add this code between the two bracket symbols:// Lines 1-5System.Data.DataTable dataSourceTable = new System.Data.DataTable();dataSourceTable.Columns.Add(new System.Data.DataColumn('Model', typeof(string)));dataSourceTable.Columns.Add(new System.Data.DataColumn('Make', typeof(string)));dataSourceTable.Columns.Add(new System.Data.DataColumn('Color', typeof(string)));dataSourceTable.Rows.Add(originalColumnValues);// Line 6GridView1.AutoGenerateColumns = false;// Line 7GridView1.DataSource = dataSourceTable;The first five lines create a data source containing three fields: Model, Make and Color. Line six sets the GridView's 'AutoGenerateColumns' property to false. This prevents the GridView from generating columns automatically when you bind it to a data source. Line seven binds the GridView to the data source. At this point, the GridView displays no columns.
Add the following code below the code described in the previous step:/ Lines 8-12BoundField boundField = new BoundField();boundField.DataField = 'Make';boundField.HeaderText = 'Ford';DataControlField dataControlField = boundField;GridView1.Columns.Add(dataControlField);// Lines 13 = 17boundField = new BoundField();boundField.DataField = 'Model';boundField.HeaderText = 'Mustang';dataControlField = boundField;GridView1.Columns.Add(dataControlField);// Line 18GridView1.DataBind();Lines eight through 12 create a bound field. This field references the data source's 'Make' field. Line 10 assigns a value of 'Ford' to the bound field. You can make this value anything you like. This is the value that appears in the new column. Line 12 adds the bound field to the GridView. Lines13 through 17 create another bound field. This bound field references the data source's 'Model' field and sets its text value to 'Mustang.' Line 18 binds the GridView to the data source.
Press 'F5' to run the application. Your Web browser will open and display the GridView and the columns you added.
In Feburary 2016 05,
Open Visual Studio. Click 'File' and select 'New Website.'
Click 'Visual C#,' and then double-click 'ASP.NET Website' to create a new website. The markup code for the default Web page appears in the center of the Visual Studio window.
Click the 'Design' button at the bottom of the window to view the form designer.
Click 'File' and select 'Toolbox.' Visual Studio will display the toolbox.
Scroll down and locate the 'GridView' control. Double-click that control to place it on the form.
Press 'F7.' The source code window will open and display this code:protected void Page_Load(object sender, EventArgs e){}This is the page load method. It runs when the Web page loads in a browser. Note the two bracket symbols below the first line of code.
Add this code between the two bracket symbols:// Lines 1-5System.Data.DataTable dataSourceTable = new System.Data.DataTable();dataSourceTable.Columns.Add(new System.Data.DataColumn('Model', typeof(string)));dataSourceTable.Columns.Add(new System.Data.DataColumn('Make', typeof(string)));dataSourceTable.Columns.Add(new System.Data.DataColumn('Color', typeof(string)));dataSourceTable.Rows.Add(originalColumnValues);// Line 6GridView1.AutoGenerateColumns = false;// Line 7GridView1.DataSource = dataSourceTable;The first five lines create a data source containing three fields: Model, Make and Color. Line six sets the GridView's 'AutoGenerateColumns' property to false. This prevents the GridView from generating columns automatically when you bind it to a data source. Line seven binds the GridView to the data source. At this point, the GridView displays no columns.
Add the following code below the code described in the previous step:/ Lines 8-12BoundField boundField = new BoundField();boundField.DataField = 'Make';boundField.HeaderText = 'Ford';DataControlField dataControlField = boundField;GridView1.Columns.Add(dataControlField);// Lines 13 = 17boundField = new BoundField();boundField.DataField = 'Model';boundField.HeaderText = 'Mustang';dataControlField = boundField;GridView1.Columns.Add(dataControlField);// Line 18GridView1.DataBind();Lines eight through 12 create a bound field. This field references the data source's 'Make' field. Line 10 assigns a value of 'Ford' to the bound field. You can make this value anything you like. This is the value that appears in the new column. Line 12 adds the bound field to the GridView. Lines13 through 17 create another bound field. This bound field references the data source's 'Model' field and sets its text value to 'Mustang.' Line 18 binds the GridView to the data source.
Press 'F5' to run the application. Your Web browser will open and display the GridView and the columns you added.
In Feburary 2016 05,
Subscribe to:
Posts (Atom)