Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox datatable

Status
Not open for further replies.

ludmann

Programmer
Apr 14, 2004
49
GB
I need to create something like a listbox, to list rows of a datatable. (in C# VS)
It needs to list contacts and attributes of that contract that are to be updated.
Like this:

Joe Smith – jsmith@coco.com
AddressStreet: Cranfield Gdns.
Website: Etc.
Barbara Cart – b.cart@bb.com
PhoneNo: 02098765
Etc.

Generally there will only be a few attributes of a few contacts to be changed, where the user has to confirm. However, when adding a new contact the attribute list will be very lengthy.

Is a listbox the best thing to use? I am also looking for simplicity.

Does anyone know any very simple example of how to bind a listbox to a datatable.

Also, I don’t have a dataset only a datatable. Is that a problem?

Any help appreciated,

Thanks,
Marika
 
I will use a ListView control to show in the main form the few columns in order to identify a contact.
Add three buttons , Edit, Delete, Add.
When Edit button is clicked then all fields of the selected item with their values are displayed in a subform with textbox for each field and also two buttons, Save and Cancel.
When Delete button is clicked then all fields of the selected item with their values are displayed in a subform with readonly textboxes and also two buttons, Apply and Cancel.
When Add button is clicked then all fields are displayed with input textbox empty and also two buttons Save and Cancel.
When Save, or Apply buttons are pressed then the datasource must be modified and the listview control refreshed.
The datasource could be from a database and in this case you should use DataSet (DataTable) to load datasource and to bind it to controls or from an ordinary xml file which also is loaded into a DataSet ( 2 lines of code).
For each Edit, Delete, Add action , the DataSet object is changed and you have to save these changes back to the xml file or to the datasource.
Another solution is to use a DataGrid and bind it from a DataView object.
Read about databinding at -obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top