C# desktop application (Data Binding)
I would like to create a simple c# desktop application which stores/retrive the user entered records into a text file. Say each record has three fields as group name, record title and record message. So Basically text file has multiple records and each record is taged with a group as below.
Group A
Header title 1A message 1A
Header title 2A message 2A
Header title 3A message 3A
....... .......
....... .......
....... .......
Group B
Header title 1B message 1B
Header title 2B message 2B
Header title 3B message 3B
....... .......
....... .......
....... .......
Group C
Header title 1C message 1C
Header title 2C message 2C
Header title 3C message 3C
....... .......
....... .......
....... .......
Group D
....... .......
....... .......
The desktopm window will have 3 columns, 1st column should list All Groups, 2nd column will list all records in a selected group (from column 1) an开发者_高级运维d 3rd column display the single record in detail which is selected in the 2nd column. Please provide your suggestions on how to implement this? Any samples and tutorial are highly apprciated.
You would better use XML.
C# has very nice XML serialization which would allow you to convert XML into c# objects and vice versa (without having to do any manual parsing)
Also, this question is a little too general. You would better try to miplement the application yourself and then come back with specific issues.
You'll need three basic components:
- The model for your data. This will likely include a
Group
class and aRecord
class, whereGroup
includes something like aGetRecords()
method or aRecords
property (returning anIList<Record>
, for data binding). - A parser that will read the lines of a file and construct a collection of these
Group
objects—perhaps in the form of aDictionary<string, Group>
or your ownGroupCollection
implementation. - A GUI (duh), with two ListBoxes and some custom display control for an individual
Record
.
For the first ListBox, you would presumably set the DataSource
property to your collection of Group
objects (this will need to implement IList
if I'm not mistaken).
Handle the SelectedIndexChanged
event of your first ListBox and set the DataSource
on the second ListBox to the result of GetRecords()
/Records
from the selected Group
.
Handle the SelectedIndexChanged
event of your second ListBox
and display the details for the selected record in your custom control.
That's how I'd approach it, anyway.
精彩评论