By hand it also gives us an opportunity to explore a

Info icon This preview shows pages 825–828. Sign up to view the full content.

View Full Document Right Arrow Icon
by hand, it also gives us an opportunity to explore a few details of the data binding system that we might otherwise not have seen, so we’ll go with that. The ListView control is in the Common Controls section of the Toolbox. When we drag it onto the top panel in the SplitContainer , we need to fix a few things with the Tasks pop up. First, we want the list view to fill the whole of the top panel—there’s a Dock in parent container task just for that. We also have to change its View —the default is LargeIcon , but we need to change that to Details for the multicolumn view we want. And finally, we need to tell it about the columns, by clicking the Edit Columns task. Figure 22-3. Pop up showing common tasks The ColumnHeader Collection Editor opens. Clicking Add a couple of times adds two columns. As Figure 22-4 shows, Visual Studio has been characteristically unadventur- ous with the names— columnHeader1 and columnHeader2 don’t say much. These are the names it will give to the fields that make these objects accessible to us in the code behind. It’s usually a good idea to provide more informative names each time you add anything in the Windows Forms designer—whether it’s a control, a nonvisual com- ponent, or a column like this. Otherwise, your program rapidly acquires a long list of incomprehensible identifiers. So we’ll set the (Name) on the right to titleColumn for the first column, and dueDateColumn for the second. Of course, we also want the displayed text in the column headers to be a bit more useful than the default, ColumnHeader , so we’ll change the Text property of the two columns to Title and Due Date , respectively. Finally, to ensure that the two columns make rea- sonably good use of the space initially available, we’ll set their Width properties to 200 and 70. Figure 22-5 shows how the form looks once this is done. We haven’t given the ListView itself a good name yet, so we’ll call it entriesListView . Controls | 801
Image of page 825

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Figure 22-4. Editing ListView columns Figure 22-5. ListView with columns 802 | Chapter 22: Windows Forms
Image of page 826
Some developers have a stylistic objection to field or variable names that include information about the type, and would argue that entriesList View is unnecessarily verbose. However, it’s quite common in UI appli- cations to have several different objects all representing the same thing at different layers—we’ve put the underlying model in a field called entries , we have the binding source representing that model to the data binding system, which we’ve called entriesSource , and we have a con- trol displaying the information, called entriesListView . Clearly these objects can’t all be called entries . We could call the control entries View , but that sounds less like an individual control and more like a description of the whole form we’re building right now. So entriesList View feels right because it seems to be a minimally descriptive and unique name.
Image of page 827

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 828
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern