|
Yes, that is probably the way I would have done it. However, given the tenor of the question I doubt that the OP could do it without a full sample of code.
|
|
|
|
|

Private Function reverseFileNameComparer() As Comparison(Of String)
Return Function(x, y) (String.Compare(Path.GetFileNameWithoutExtension(y), Path.GetFileNameWithoutExtension(x), StringComparison.OrdinalIgnoreCase))
End Function
Private Sub AddToCombo(combo As ComboBox, directoryPath As String, filter As String)
combo.BeginUpdate()
For Each fn As String In Directory.EnumerateFiles(directoryPath).OrderByDescending(Function(f) (Path.GetFileNameWithoutExtension(f)))
combo.Items.Add(Path.GetFileNameWithoutExtension(fn))
Next
combo.EndUpdate()
Dim files() As String = Directory.GetFiles(directoryPath, filter)
Array.Sort(files, reverseFileNameComparer)
combo.Items.AddRange(Array.ConvertAll(files, AddressOf Path.GetFileNameWithoutExtension))
combo.FormattingEnabled = True
combo.DisplayMember = "Name"
combo.BeginUpdate()
For Each fio As FileInfo In New DirectoryInfo(directoryPath).EnumerateFiles(filter).OrderByDescending(Function(f) (f.Name))
combo.Items.Add(fio.Name)
Next
combo.EndUpdate()
End Sub
Private Sub cboFileInfo_format(sender As Object, e As ListControlConvertEventArgs)
Dim f As FileInfo = DirectCast(e.ListItem, FileInfo)
e.Value = f.Name.Substring(f.Name.LastIndexOf("."c) + 1)
End Sub
|
|
|
|
|
What Richard said. Not what Wombaticus said. Sorting is easy.
This replaces your posted code except the try-catch-block:
Dim dirAccessFiles As String() = Directory.GetFiles("H:\FilesTest", "*.accdb") _
.Select(Function(x) Path.GetFileNameWithoutExtension(x)) _
.OrderByDescending(Function(x) x) _
.ToArray()
cboAccessFile.Items.AddRange(dirAccessFiles)
(You'll need an "Imports System.Linq" at the top of the file.)
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
You might want to pass StringComparer.OrdinalIgnoreCase to the OrderByDescending function, since file names in Windows aren't case-sensitive.
If you want to mimic the "natural" sort order that Windows Explorer uses, you'll need a different comparer - for example: Numeric String Sort in C#[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Good suggestion; also the linked article, thank you!
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Hello !
On Entity Framnework 6 , when update model from database , I choose on refresh tab , only one or some of the tables , but after the process finish the entire model is recreated.
Is there any way to force recreating only some of the classes ?
|
|
|
|
|
|
In a Visual basic.net 2010 desktop application, I am loading a list of Access 2013 files that the user needs to select to work with. The code listed below is correct but the file names are too long for the combo box.
Here is the code:
Try
Dim dirAccessFiles As String() = Directory.GetFiles("H:\FilesTest", "*.accdb")
Dim dir As String
For Each dir In dirAccessFiles
cboAccessFile.Items.Add(dir)
Next
Catch except As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
Thus I have the following questions to ask you:
1. If there is a way to expand the size of the combo box values while the application is executing, can you show me how to do that?
2. Right now in dropdownlist box, the values look like,
'H:\Testfiles\Diane__Currentyear.accdb'.
I would like the value only of 'Diane__Currentyear' that is listed above to display. Also where hardcoded value of 'H:\Testfiles' is displayed in the code above, I will get the actual value from the app. config file.
Thus would you show the code on how to display only the value of 'Diane__Currentyear' in the list of combo box values?
|
|
|
|
|
classy_dog wrote: 1. If there is a way to expand the size of the combo box values while the application is executing, can you show me how to do that? I suggest an alternative, which is more elegant IMO. This article: Adjust combo box drop down list width to longest string width[^] and maybe additionally dock the ComboBox horizontally in its container so that the user can adjust its width by expanding the window horizontally (see the Dock-property of the ComboBox-control in the designer).
classy_dog wrote: I would like the value only of 'Diane__Currentyear' that is listed above to display. Path.GetFileNameWithoutExtension[^] does the trick.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
... and if you don't want that the path is displayed in the Combobox you can write :
cboAccessFile.Items.Add(dir.replace("H:\FilesTest\",""))
|
|
|
|
|
Hello !
I have a partial class that is generated automatically . Each property is defined without Set get.
I have created manually another partial class where I have defined the same properties with Set , get.
But I'm getting error for duplicate properties.
Is anything I can do on my partial class ( that I have created manually ) , in order to not get error messages ? ( I mean without deleting the auto-generated partial classes )
Thank you !
|
|
|
|
|
satc wrote: Each property is defined without Set get. I assume you mean that the auto-generated properties are auto-properties (as properties must have a getter or setter at least, otherwise it would be a field).
One option would be to delete the auto-generated properties from the auto-generated partial class. Which obviously has the disadvantage that you need to do this every time the code is newly generated.
If the code for the getter/setter you're implementing is only for INotifyPropertyChanged and/or similar generic stuff, you could probably edit the T4-template for the code-generator, as previously suggested by Dave.
Or edit the T4-template so that the properties aren't generated at all.
Another potential option would be to name the properties in your manual partial class differently or edit the T4-template to name the auto-generated properties differently (with a prefix or suffix). But I don't know how that would work out with EF; you would have to test it.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I've read somewhere about using MetadataType on my manual Partial class , but I don't know if this can be used in my case ?
If yes , how ?
Thank you !
|
|
|
|
|
satc wrote: I've read somewhere about using MetadataType on my manual Partial class , but I don't know if this can be used in my case ? I wouldn't know how it could help here, seems completely unrelated to me.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I found this article :
http://forums.asp.net/t/1885808.aspx?Update+edmx+file+without+effecting+currently+generated+model[^]
Look at the last post.
I've done exactly the same thing , but doesn't work for me.
I Don't know why ?
This is my code :
Original classes ( auto generated )
Partial Public Class Myobj1
Public Property id As Integer
Public Property prc As Decimal
Public Property categ As Integer
End Class
My partial classes using the article suggestion :
Imports System.Collections.Generic
Imports System.ComponentModel
Imports MyProg.MyObj1
<MetadataType(GetType(MyObj1MetaData))> Partial Public Class Myobj1
Friend NotInheritable Class Myobj1MetaData
Implements INotifyPropertyChanged
Private privatprc As Decimal
Public Property prc() As Decimal
Get
Return privatprc
End Get
Set(ByVal value As Decimal)
privatprc = value
OnPropertyChanged("prc")
End Set
End Property
Private privatcateg As Integer
Public Property categ() As Integer
Get
Return privatcateg
End Get
Set(ByVal value As Integer)
privatcateg = value
OnPropertyChanged("categ")
End Set
End Property
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub OnPropertyChanged(ByVal propertyc As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyc))
End Sub
End Class
End Class
This code shows no error , but the InotifypropertChanged that I want to implement , it's not working at all.
|
|
|
|
|
I see how you might get the idea that it could help here but the thing is: It's only intended to be able to provide attributes to auto-generated properties without them being overwritten by EF when the entities-classes are newly generated. The properties in the meta-data-class that's being assigned to an entity-class by the MetadataTypeAttribute only serve the purpose of matching by name to the auto-generated properties through reflection. Any code in their getters/setters will be ignored because they're never actually called.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
How to know the file size of any format (mp3 , text , or exe ,etc) using vb code and store , plz help me , suggest something useful.
Thank you
|
|
|
|
|
File size "of any format"? There's no such thing. File size is determined by the complete content of the file, not the content format.
|
|
|
|
|
Use system.IO to locate the file and read the attributes, one if which is the size. this does not care what the format of the file is!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello !
I'm using entity framework 6.0 , DBContext ,Database First.
I have created the model form an existing database using step by step wizard.
In some classes , I need to implement INotifyPropertyChanged , so I have created some partial classes ( outside the model class files ).
Everyhting is working , but I have problems when I change something on database and I need to update the model from database.
Because the model is recreated with all classes , and I get errors like this :
Error 103 'Public Property dt1 As Date' has multiple definitions with identical signatures.
So I have to manually delete all the duplicates from model classes and to keep those in partial classes where I have implement INotifyPropertyChanged.
But if I update again the model , the classes are recreated again , and I have the same problem.
Is there any way to resolve this problem?
Thank you !
|
|
|
|
|
There's nothing you can do to prevent the classes from being recreated so you can't put your code on them.
But all may not be lost. As far as I remember reading (it's been a long time!), Database First generates templates that can be modified where you can put your code that will show up in the generated classes. I don't have an example of this as I've never used Database First. I always use Code First.
Search your project for *.tt files. These are the T4 templates that you need to modify. You can read more about these templates here[^]. Of course, there's always Google[^] for even more information.
|
|
|
|
|
In a VB.NET 2008 desktop application, I need to add some initial selections with a corresponding button to the 'main' form, before any of the normal
processing is allowed to occur. Thus due to that fact, I have the following questions to ask:
1. This application is using a System.Windows.Forms.MainMenu and I would like the 'File' option to not display until the 'new' button is clicked? If this is
possible, would you showe me the code for this to occur?
2. If option #1 is not possible, is there a way to make System.Windows.Forms.MainMenu not display until the the 'new' button is clicked? If this is possible,
would you show me the code for this to occur?
3. In this application there is code that adds menu items with logic like,
MainMenu1.MenuItems(0).MenuItems.Add("New Item", New EventHandler(AddressOf ClickHandler))
MainMenu1.MenuItems(0).MenuItems.Add("-")
Is there a way to modify the order of list of menuitems after the menu items have already been created? Would I need to delete the menuitems at that point and create the menuitems again? Thus would you show me the code for this option and/or let me know if this option is not possible?
|
|
|
|
|
1. Set the menu item's visibility property to False so it will not show on the form. You then set it to True when required.
2. NA
3. You would need to delete them and re-insert them.
|
|
|
|
|
In response to your answers, I have the following questions:
"Set the menu item's visibility property to False so it will not show on the form. You then set it to True when required." I placed the following code in the application, and it did not work:
MainMenu1.MdiListItem.Visible = False
Thus can you show me the code to Set the menu item's visibility property to False?
Also would you show me the code on how to 'You would need to delete them and re-insert them' the menuitems? The menu items are currently created in the gui and not in code.
|
|
|
|
|
classy_dog wrote: can you show me the code to Set the menu item's visibility property to False? The code you have should do it, I just tested it on my sample and it works fine.
The menu items are created in code within the form designer, whose code can be viewed, so you can see how it is created. You can also read the MSDN documentation[^] for full details.
|
|
|
|