Possible with Listbox?

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Hi All,

In one of my apps I have a documentation field. This is where the user would browse (using OpenFileBrowser) and select a document that they want to use for that record.
However, I've expanded on this as they may require more than one document, from different folders.

I have replaced my link label with a listbox, and when I browse to a document and select it, it is successfully added to the listbox. When I doubleclick that item, I have got it working so that the document opens.

My problem now lies with binding this listbox to the database Documentation field.
I want each item in the listbox to appear in the database field, not just the SelectedItem.

Is this possible?

Cheers,
Luke
 
2 cents worth...

V-B, reading this post I noticed you are attempting to contain a one to many relationship in one field of one table. Seems to be inherently difficult and will surely add to programming time/difficulty. Have you tried adding a table "documentation" with a link back to this table? This problem (area for improvement) implies a Master-Detail relationship and should be handled as such.

You certainly could get the items of the listbox and create a string to save in the documentation field, then parse the field for each record and dump it back into the listbox - easy, huh?

Just thinking out loud,
Hope it wasn't annoying.
 
Personaly I think that DavidT has got the best solution... at least that's how I would deal with it. You try t ostuff too muchinfo into one field and you'll run out of room very quickly.

-tg
 
Database Design

Interesting, coming from Kulrom.
Far too often the coding of the project begins before the database has been established or even planned. Successful projects begin by mapping out the database and determining what the table requirements (fields and relationships) will be; not to mention what is already established. Basic database structure should be addressed and mapped out; keeping in mind the database is a 'living' entity and should change and evolve into the collection of data necessary to complete your goals. That said, initial planning would have specifically targeted the above table structure as unsound, and a detail table would have been logical. Keep in mind, mindlessly adding tables to keep your current project happy can quickly add up to a tangled mess of seldom used or redundant tables and an indecipherable database.

Kulrom, what database do you use? I use SQL2000, which interestingly enough is defined as a relational database engine. Seems like that would be the place to maintain and establish relationships.

Just thinking out loud.
 
Soz for getting back today, I'm still waiting for broadband to be connected at home, and our work firewall blocks Yahoo and MSN IM.

I see David's point, I hadn't actually thought of that at first, as originally my spec was to have a documentation field that would only have a path to one document.

I am in the process of trying to implement that on my project to see if that will do the job.

Kulrom - what exactly do you need to know, most of the info on my problem is in this post.
To recap:
- Field in table in database (SQL2000) called Documentation. Stores path of document, defined by OpenFileDialog browser.
- Now have been told that more than one document path may be required to be stored. Want to keep just 1 field (Documentation) but store each path in this field, i.e. "c:\test.doc;c:\test2.doc;c:\test3.doc" with the ; acting as a splitter
- On my form I want to display each of those paths seperate to one another, so that when a user double clicks i.e. "c:\test.doc" then that document opens.
- On another form (New Record), I want the user to be able to browse using FileOpenDialog (I've done this bit), and store document path (s), and when the dataSet is updated, any paths are purged into one string, with ; splitting each path.

Thanks guys!
Luke
 
Parse the string and add to listbox with a loop

This code loops through the string grabbing out the URLs based on parsing by the location of the ";" separating the data. When you are saving the data you add the ";" by:

Dim strNewData As String = objTable.Documentation

Then update the table with new Urls by

objTable.Documentation = strNewData & ";" & strFile'File URL string from browse input

To add the URLs to list box from a data record:

Dim strUrlDataRecord As String = "Your url data here; Your url data here" ' data from the documentation field
Do While strUrlDataRecord.IndexOf(";") <> -1
Dim strParsed As String = strUrlDataRecord.Substring(0, strUrlDataRecord.IndexOf(";")) 'Start index, length gets you to right before the ";" - the URL value
lbxURLIn.Items.Add(strParsed)
strUrlDataRecord = strUrlDataRecord.Remove(0, strUrlDataRecord.IndexOf(";") + 1) 'Removes up through the ; so you are ready to loop through and get next URL value.
Loop

This should work. You might have to tweak the .IndexOf values a little - I am never sure without running the code whether the substrings are parsed at or in fromt of the index values. Should be pretty obvious based on the values that come into the listbox.
 
Cheers bob,

I was just about to reply with I've got it sorted, using David's solution.

I've had to heavily tweak my application, but it's actually helped out - it's made me tidy the whole back end and front end up!

Thanks for your help guys!
Luke
 
Back
Top