|
|
Private Sub LoadCustomer()
Dim m_c As New ClassCustomer
Dim arr As New ArrayList
arr = m_c.LoadCustomer()
With comboCustomer
.DataSource = arr
.DisplayMember = "Name"
.ValueMember = "ID"
End With
arr = Nothing
m_c.Close()
m_c = Nothing
End Sub
|
|
|
|
|
Well there you go. Try Convert.ToInt64(whatever) - it won't do that for you by itself.
However, a long should convert to an object, it should just box it for you.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hey, I'm trying to display the contents of a text file that I've selected from a ListView in a RichTextBox. So far I've found that I can't get the file name from the ListView, and I'm having extreme difficulty in finding a way to pull the PIDL instead.
My current code doesn't show that I'm trying to read the file inside the RichTextBox yet, as I work in steps confirming everything individually, and currently I can't validate the file name requested. So my MAIN concern is getting the file to open based on the selected item from the ListView. (anybody willing to help with the stream reader or other means to read in the text box will be happily accepted.)
When I select an Item from the ListView I get an exception / error stating : "The system can't find the file specified "........ any ideas?
current code is as follows:
p.s. if i change to the "'("c:\test.txt")" the code works as requested and opens the specific file (note, this is not a file listed in the ListView, only a test subject file)
Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
Dim ListViewItem As New ListViewItem
Try
System.Diagnostics.Process.Start(ListViewItem.Selected) '("c:\test.txt")
MsgBox("help me", , MessageBoxButtons.OK)
Catch ex As Exception
MsgBox(Err.Description, vbCritical, "Error " & CStr(Err.Number))
End Try
End Sub
Why is common sense such an un-common comodity?
|
|
|
|
|
wetrivrrat wrote:
p.s. if i change to the "'("c:\test.txt")" the code works as requested and opens the specific file (note, this is not a file listed in the ListView, only a test subject file)
What is the value you're getting back from the list view ? Is it the name of a file, and you need to qualify it with a path name ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm using "For Each drive In Environment.GetLogicalDrives()" to load a TreeView, then showing the folder contents in the ListView, so the value of the ListView Item would be shown onscreen as "sites.txt", "testdoc.txt", etc....
and then loading the ListView like this:
Dim dirInfo As DirectoryInfo = New DirectoryInfo(e.Node.FullPath)
ListView1.Items.Clear()
If (dirInfo.Exists) Then
Dim fileInfos As FileInfo() = dirInfo.GetFiles()
Dim info As FileInfo
For Each info In fileInfos
Dim item As ListViewItem = New ListViewItem
item = ListView1.Items.Add(info.Name)
item.SubItems.Add(info.LastAccessTime.ToString())
Next
End If
just for laughs I cut the system.diagnostics line out and put this inplace-----
RichTextBox3.LoadFile(openfile1.FileName, RichTextBoxStreamType.PlainText)
When I did this I get a new error which states :"Empty path name is not legal"
which seems self-evident that the problem is clearly the ListView is not keeping the path name its only displaying the text 'returns' from the TreeView. I also changed the line "item = ListView1.Items.Add(info.Name)" to show (info.fullName) and I still get the "Empty path name is not legal" error.
Also, I removed the "openfile1.FileName," from the LoadFile statement and I get the following error: "Could not find file "G:\VB.net\Slider tests\bin\1" " so it looks like its not even seeing the true pathname....
thanks
Why is common sense such an un-common comodity?
|
|
|
|
|
You've got a couple of problems. The ListViewItems don't have the full path to the files because you never saved the full path in them. You need both the filename so you can show the user just that, the short filename, and you need the full path to the file so your code can get it easily. You're only doing one of those things.
The ListViewItem class has a Tag property that can store just about any type of object. In your code, it's probably a good idea to store the full path to the file in there so you can retrieve it later when you go to open the file.
Dim dirInfo As New DirectoryInfo(e.Node.FullPath)
If (dirInfo.Exists) Then
ListView1.Items.Clear()
Dim fileInfos As FileInfo() = dirInfo.GetFiles()
Dim info As FileInfo
For Each info In fileInfos
Dim item As New ListViewItem(info.Name)
item.SubItems.Add(info.LastAccessTime.ToString())
item.Tag = info.FullName
ListView1.Items.Add(item)
Next
End If
Now, your second problem. When you go and open the file in your doubleclick handler, you're actually creating a new instance of a ListViewItem, a blank one!, and using that to supply the filename your trying to launch. Obviously, you can't do that. You have to use the selected item in the ListView.
Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
Try
System.Diagnostics.Process.Start(ListView1.SelectedItem.Tag)
Catch ex As Exception
MsgBox(Err.Description, vbCritical, "Error " & CStr(Err.Number))
End Try
End Sub
* Note: The code in this post has NOT been tested.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Gosh - go and sleep for 8 hours, and next thing you know, someone's taken over !!!!
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Well, now that you're awake.........
I tried Dave's code and I can't seem to get it to work.....
1st. not sure if its due to something else higher up in my code or just a miss-spelling but I can't use ListView1.SelectedItem.Tag, as I have to use ".SelectedItems.Tag" after that change I am unable to then use "Tag" as "Tag is not a memeber of System.Windows.Form.ListView.SelectedListViewItemCollection"
2nd. since I can't use Tag I looked at what .net says I can use and here are my options:
(Clear, Contains, CopyTo, Count, GetEnumerator, GetType, IndexOf, IsReadOnly, Item.)
Plus like I said last night my ultimate goal is to load this txt file to a RichTextBox placed next to the ListView, so I'm not so concerned with the System.Diag.... since that will open the file in its own program. I'm currently thinking of Streamreader as an option.....
Why is common sense such an un-common comodity?
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
|
|
|
|
|
wetrivrrat wrote:
Well, now that you're awake.........
ROTFL - barely...
wetrivrrat wrote:
".SelectedItems.Tag" after that change I am unable to then use "Tag" as "Tag is not a memeber of System.Windows.Form.ListView.SelectedListViewItemCollection"
Gosh - you're getting a bit confused here. A SelectedListViewItemCollection contains SelectedListViewItems. I've just mocked up a VB.NET project ( I hate how you can't add events in the form designer, but.... ), here's my code:
Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
Dim ListViewItem As New ListViewItem
Try
System.Diagnostics.Process.Start(ListView1.SelectedItems(0).Text)
Catch ex As Exception
' This is a BAD idea - catch only the exception that you foresee as being likely, in this case:
' System.IO.FileNotFoundException()
MsgBox(Err.Description, vbCritical, "Error " & CStr(Err.Number))
End Try
End Sub
Also, forget this Err.Number drivel, it's a holdover from VB6, isn't it ? It's sure a waste of time. You have an exception object which will give you a detailed error string and a call stack, so use it. The main reason I hate VB.NET is that they didn't deprecate all this stuff that VB6 users will keep using, although they shouldn't. While we're at it, don't use CStr, use .ToString, that's what it's for.
So if multiselect is turned off, there'll only be one selected item ( there has to be one, there was a double click event ). So you grab it using SelectedItems(0), and then you have the item, you can grab column values if needed, I just used .Text to get the text displayed on screen. Now, the only issue is if you're showing a filename and not a full path, you need to rebuild your path for the execute command to work.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
k...
so I'm glad that this has worked for you on your side... currently I must be looking at only the filename and not the fullpath as I get an error stating the file cant be found....multiselect is off and the only reason for the doubleclick is becuase I expect to have massive txt files that I don't want displaying everytime a user hovers over the filename(and I wanted to simulate the process for doubleclicking to open a filefolder,etc, as the expected audience won't understand the single click ).
Good catch on the SelectedItems(0) I removed that from an earlier sub becauase it was restricting me to only the first listing, and I forgot to put it here(was assumeing the same would happen... )
The confussion re: the "Tag" was because the editor didn't like the use of 'tag' and that was the error it gave in response to Dave's code
Currently the ListView shows the entire filepath as I was just showing filename, had the same probs having now and used fullpath to test....never changed it.
re: rebuilding paths for executing commands....I can't even get the node text to show in a textbox....I'm feeling like I'm missing the biggest part of my day, like I walked out side with no pants on or something.... why don't they have a "Brain Fart" icon smiley face?
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
wetrivrrat wrote:
The confussion re: the "Tag" was because the editor didn't like the use of 'tag' and that was the error it gave in response to Dave's code
Yeah, I can't see a 'Tag' property, although I didn't look too closely, the (0) was obviously a major part of your problem, inserting it could well make Dave's code work.
wetrivrrat wrote:
re: rebuilding paths for executing commands....I can't even get the node text to show in a textbox....
How do you mean ? Is this a new question ?
If file names are unique and you don't want to show them, you can hide them in the listbox, or you can build a filename->filePath hashtable before you show the list.
wetrivrrat wrote:
I'm feeling like I'm missing the biggest part of my day, like I walked out side with no pants on or something....
LOL - I feel like that all the time....
wetrivrrat wrote:
why don't they have a "Brain Fart" icon smiley face?
Obscenity laws. :P
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
YES!!!! ok, so the problem was because I had mulitselect disable and was not telling the code to look for a path... insert dave's 'tag' and your '(0)' and I feel like I at least have found my shorts, even if they were in the MAILBOX! thanks so much!!!
k.. so, this fixed the 'tag' problem, and the node title in the textbox...(which wasn't a new question, but rather just a statement...an additon to my delima, sorta)...
again thanks
till next time.......
"To all the beautiful people...including myself...."
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
No worries, glad to help.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
My bad. That's what happens when I try to write code from memory. Christian's right. The doubleclick handler should look like this:
Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
Try
System.Diagnostics.Process.Start(ListView1.SelectedItems(0).Tag)
Catch ex As Exception
MsgBox(Err.Description, vbCritical, "Error " & CStr(Err.Number))
End Try
End Sub
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Yeah, and from the mistake I posted, it looks like I went to sleep right before I started writing the post!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
LOL
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi I need to create program to connect my VB.NET to MS Outlook and import all messages to database (Access). Does anybody know how to do it. Thanks
|
|
|
|
|
Depends on your version of Outlook. If your using Office XP and above, check out the MS Office XP Primary InterOp Assembelies.
hope this helps.
|
|
|
|
|
I am trying to develop a new usercontrol that has a default image I need to load. I have an embedded bitmap and using the following code to retrieve it.
Dim executing_assembly As System.Reflection.Assembly = Me.GetType.Assembly.GetEntryAssembly()
' Get our namespace.
Dim my_namespace As String = executing_assembly.GetName().Name.ToString()
' Load three pictures.
Dim picture_stream As Stream
Dim bm As Bitmap
picture_stream = executing_assembly.GetManifestResourceStream(my_namespace + ".Checked.bmp")
If Not (picture_stream Is Nothing) Then
bm = New Bitmap(picture_stream)
picturebox.Image = bm
picture_stream.Close()
End If
When i reference my control(dll) and try to use it in another app. it does not work all i get is Object Reference not set to an instance of an object.
But when i use the code by its self in another project it works.
What it boils down to is how can i store/embed an image in a usercontrol dll.
Thanks in advance.
Mark Thibodeaux
|
|
|
|
|
tibmark wrote:
Dim my_namespace As String = executing_assembly.GetName().Name.ToString()
The executing assembly is not the same as the dll, if the code is in a dll. You'll need to get the name that's required for your dll, either by a different method, or by hard coding it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I was wrong it comes back null is not a valid vaue for stream. i am fairly new to the creation of usercontrols any examples would be very helpful.
Mark Thibodeaux
|
|
|
|
|
Usercontrols have nothing to do with it. You've obviously copy and pasted this code, do you have any idea what it does ? Resources are stored in your file and retrieved using a fully qualified name. You're building the name by asking what the name of the application that is running is, but that's not the name being used in your dll, which has a different name. Have a look at the string that's being generated, and then replace the application name with the dll name, that should work. I've never pulled resources from a dll before, but I'd imagine that would be the way forward.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yes that is what i did, i couldnt find the rigght info just code. So let me ask the question the right way i would like to make a usercontrol that hosts a few bitmap images. what is the best way to do this or can you point me in the right direction. I am doing what i can to learn on limited resources and no real experience.
Mark Thibodeaux
|
|
|
|
|
Easiest approach - why not just load the files from disc ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|