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
 
Hi Kulrom,

there really isn't any code at the moment. It's something I want to know whether it's possible to do before I attempt to do it!

Basically what I have at the moment;

Form, with listbox (lstDoc) and button (btnBrowse). Press Button;

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] btnBrowse_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] btnBrowse.Click
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] x [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OpenFileDialog
[/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] x
.InitialDirectory = "s:\"
.Title = "Browse for DWR Supporting Documentation"
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] .ShowDialog = DialogResult.OK [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]lstDoc.Items.Add(.FileName)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]

Any document that is selected from the OFD is then added to the listbox. The user can then browse again, and add another document, and so on and so on.
If they doubleclick an item in the listbox, it opens that document using process.start.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] lstDoc_DoubleClick([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] lstDoc.DoubleClick
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strDoc [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = lstDoc.SelectedItem
Process.Start(strDoc)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE]

Originally on my ADD_FORM, I was using a link label to store the document path. But it's had to be expanded due to the fact there may be more than one document needed for that record (Works Request) in different folders. So I thought a listbox would be a better approach.
However, now I need to figure out how to save the items into my database field (table field name = Documentation, Varchar 1000) and then have the listbox on my VIEW_FORM to understand that and have each item on a seperate line.

How to go about it I'm not sure, perhaps it isn't possible......

Luke
 
No...I've got the listbox item click sorted, it is to view the document that is listed.

My question from the start is how to save the items that are listed in the listbox to my database - to only 1 field.
I.E.
Listbox shows

s:\Documents\Doc1.doc
s:\Documents\Doc2.doc
s:\Documents\Doc3.doc

I want those 3 items to show in my table, in the one field, like...

s:\Documents\Doc1.doc;s:\Documents\Doc2.doc;s:\Documents\Doc3.doc

with the ; acting as a splitter, so then the list box recognises each as a seperate item when it lists them.
 
Maybe its better to start from scratch and see if someone knows the best way of doing it, maybe using a listbox is the wrong way.

I have a field called Documentation. It is used by a file browser to add a path to a document in relation to the Works Request being recorded.

However, more than one document may be required, this is an unknown number. Each document may not exist in the same folder, so FolderBrowser is out of the question.

The document path must also be so it can be opened and viewed. This is achieved currently by storing the document name on a link label and using process.start

What is the best way of achieving this, bearing in mind that the Documentation field in my database is only 1 field, I don't really want to have to have 3 or 4 fields to store different documents, as not all work requests will have this many, and some may have more.
 
I like the way you say "easy" !!!!

I've tried a few things I found on the web but none of them work as expected. I tried working it out for myself but ended up with errors (figured out it came from me trying to dataBind).

I can't wait to see your solution, if it works then a virtual pint on me!

Luke
 
I've just had a thought....

I have two forms, 1 to add a new record and the other to view the records in the DB.
For the add form, I need to add items to the listbox and then store them in the field when the record is submitted.
For the view form, I need to view the field as items in a listbox, with the possibility of those items being updated / removed / added to.

Luke
 
hey if can suggest u; can u use datagrid instead of listbox. This will help u in adding , editing and deleting the records and it is easy to use. In one of my application i to had the same case i used datagrid for adding and viewing the details for the same data.
 
Back
Top