Instantiate And Name Listbox Dynamically?
Jun 5, 2009I want to instantiate and name a listbox based on the value of a textbox. If the listbox already exists by this name (textbox value) I want to add items to the list.
View 14 RepliesI want to instantiate and name a listbox based on the value of a textbox. If the listbox already exists by this name (textbox value) I want to add items to the list.
View 14 Replieshow to add listbox item to another,when listbox r created dynamically.
View 3 RepliesI am pulling data in from a query, where three of the columns are being put into the same Listbox.Does anyone know of a sort statement to sort it alphabetically after inserting the data into a listbox, or would I be better putting the results of my query into three arrays and then putting them the arrays in, in the order I want them in.
View 2 RepliesI am passing some values from a Gridview Update Click event to a popup ASP.net page that dynamically builds a series of textboxes in a Placeholder based on the number of sentences that are found in a specific cell of the Grid Row selected.The boxes that are built represent each sentence found in the cell of the selected row. Each sentence is presented for translation, where user enters data into a 2nd dynamically generated textbox.This all works great.Now I have a Listbox beside the 2nd textbox, which sometimes has 1 or more variables that need to placed into the translated sentence. I have set up a Hover menu over the listbox so that I can select the variable and insert it at the end of the sentence in the 2nd textbox. My problem is generating the click event on the dynamically created Listbox. Something like....
Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox1.Text = TextBox1.Text & ListBox1.SelectedValue
[code]....
I want the ability to auto stretch the listview control column when the form gets resized in vb.net 2008 These are the properties I am mentioning for the ListView now :
ListView1.View = View.Details
'ListView1.GridLines = True
ListView1.FullRowSelect = True
[code]....
I am increasing the width of control and not columns as I wanted. I am unable to find anything else than width.
If I have a console application containing the class
[Code]...
I'm not a VB.NET guy. Am I correct in assuming I need to instantiate my object first? Why does the VB.NET example differ?
I have created a WebSite with a folder called Classes. In the folder, there is a class with a Public Shared Function. How do I go about instantiating that class so I can use that function on a web form?
View 5 RepliesI'm trying to decide whether to get a value, call it X, in my class through a read only property or through a function. Normally I'd code it as a property except in this case the GET involves doing a lookup to a sql table. So there's way more overhead than a simple RETURN X. So my question is, when I instantiate a new object from my class, are all the properties calculated at that point, so that the sql lookup will occur too? Or is the property only evaluated when I actually reference it in the calling code.
View 3 RepliesI sort of understand why this is happening, but not entirely. I have a base class with a Shared (Static) variable, declared like so:
Public Shared myVar As New MyObject(arg1, arg2)
In a method of a derived class, I set a local variable like so:
Dim myLocalVar As MyObject = myVar
Now when I do something like myLocalVar.Property1 += value, the value in Property1 persists to the next call of that method! I suppose I get why it would be happening; myVar is being set by reference instead of by value, but I've never encountered anything like this before. Is there any way (other than my workaround which is to just create a new object using the property values of myVar) to create myLocalVar by value?
i wanted to do something simple that sort of replicate an object:
public function clone(byval realcopy as object) as object return new Control ' something like this works, however i want to return the type of realcopy, which may not be a control end function so i tried this:
public function clone(byval realcopy as object) as object
return new gettype(realcopy.gettype)
end function
Just a bit of an issue that we're trying to resolve here. Assuming We're implementing a business model as one dll and a data access layer as another dll. We want them to be de-coupled so we implement an interface for the data-access layer. Great, we could now swap out the data access layer and, as long as the new data access layer fulfils the interface we're good to go, right?
Except we're not. In the business model we need to insanciate the data access layer and, because you can't instanciate an interface, you have to instanciate the actual class. We need to know the name space and the class name.We're going to end up with a line of code somewhere in our business model that looks something like this:-
Dim test as iDataLayer
test = new namespace.DataLayer
Basically, we can declare test as an iDataLayer (the interface) but to instanciate it we need to refer to the actual class (DataLayer). So we haven't really removed the coupling. If we want to swap out the data layer for a different implementation with a possibly different class name or namespace then we need to ammend the code in the business model. We're trying to avoid that.
So far the best we can come up with is to use the activate instance method instead of the New keyword (Late Binding). Because that takes a string we could hold the namespace and classname in a config file or similar, so swapping out one component wouldn't invalidate the others, you'd just need to update the config. That's just our home-spun solution though and I can't help feeling there are betters ways out there.
I'm trying to figure out if it is possible to instantiate and invoke a delegate by name, rather than explicitly. I think the code below explains it fairly well. I want to accept a function name and then instantiate the delegate based on that. In the example I use a select case, but I want to eliminate that and just use the methodName argument itself.
Private Delegate Sub myDelegate()
Private Sub myDelegate_Implementation1()
'Some code
End Sub
Private Sub myDelegate_Implementation2()
[Code] .....
I have defined an interface named IEmployee (ID, FirstName and Surname properties) but I have not yet implemented that interface in any class. What I want to do is something like:
Dim User as New IEmployee
User.ID = 1
User.FirstName = ""
User.Surname = ""
Call SomeFunction (User)
The VB.NET complier does not seem to like this.
what actually goes on inside the pc when I reference an object vs when I instantiate it.
Like this
Guys joe; (reference)
Joe = new Guys; (instantiate).So what goes on inside the computer for each line above.
this is what i want to do. I have a class library project into my solution. Into it i have a class. I want that class to be instantiated as soon as the solution starts. So it can be accesible from the other projects in the solution like this: Namespace.InstanceOfTheForm.Property Is there any way to do that? or something close to that?
[Code]...
I used different backgroundworkers to instantiate some 'heavy' forms thinking that it will reduce the time to instantiate them if I did them at once but it looks like I am wrong since it is still taking about 43 seconds to load all of them. Am I missing something or do you have a tip on how I can speed up their instantiation?
View 15 RepliesPresuming "instantiate" is the appropriate terminology, may I get some insight as to which of these are better, more efficient,[code]...
View 3 RepliesI am having some real issues with this one. I have a class which contains two other objects...but I cannot seem to instantiate those sub objects. Here is the code for my class:
Code:
Option Explicit On
Public Class Boot
[code]......
I am currently playing around with VB.Net using Visual Studio 2010 (.Net 4.0) and I need your help to create a collection class (let's call it 'cl_MyCollection') with a constructor that accepts two arguments:An SqlDataReader object Some means of pointing to a custom class I have created.I have five database tables in SQL 2000 and five VB.Net custom classes.Each custom class contains a variable for each field of the table the class represents.For example:"tbl_User" has 2 fields "User_ID" and "User_Name" and tbl_Family" has 3 fields "Family_ID", "Family_Name" and "Family_ Location". [code] Fixed typo, the select case now points to the second argument ('selectedClass') as originally intended.
View 2 RepliesI have an application which I am trying out on machines without mysql. The app runs fine on my local host however when I try to use the application on another machine I am getting the following error:
Access denied for user 'root'@'localhost (using password: YES)
Then I get a .net framework error
System.NullReferenceException: Object reference not set to an instance of an object.
I thought I had exported the DB but I was left with a mysql file which I placed in the bin directory.
i've got a generic class for xml serialization and deserialization.
Public Class clsXMLHandler(Of T)
Public Sub serializeFromObject(ByVal filePath As String, ByVal [object] As T)
Dim creater As New FileStream(filePath, FileMode.Create)
Dim xml As New XmlSerializer([object].GetType)
xml.Serialize(creater, [object])
[Code]...
I'm sure I've seen this done in 4.0 but can't remember how it is done.
Basically I want to instantiate a class and call a method of that class on the same line of code.
So something like this
Dim s as String = new myClass().getTestString()
I see a sample code that an object is instantiated within the class definition block. But when I test the folllowing, I got error "Process is terminated due to
[Code]...
I have a WPF windows project with a base Window, and then a series of user controls which I want to add at runtime based on a string from a file. I'm reading a string say "controlA" and i want to create an instance of the user control with the class name "controlA" and then add it to a base window. I want to have a constructor, but for now I would just like to see it work without.I need to do this: read a string (which is the user control type), create an instance of a user control based on that string, and then add the instance to the current WPF window. I've been playing around with Reflection.Assembly, getType, System.Activator.createInstance, Invokemember, CreateObject, and a few others. I can't seem to get it to work.
View 5 RepliesSystem.String is a class type, but why we can use it without instantiate it with New keyword?
For example:
Dim CommandLineParameters As String = Microsoft.VisualBasic.Interaction.Command
No new keyword being used at all?
I am trying to run a backgroundworker to load data from my DAL (which is available in another class). I want to keep the UI available and not have the "locked up" feel while the object is loading.When I create a simple backgroundworker and Sleep the UI stays responsive and my controls can be updated after the sleep. As soon as I replace the sleep with a call to instantiate the object from my DAL, the UI locks up. Is there someway I can instantiate this object using the background worked and keep the UI responsive?
When the situation object is instantiated it could take several seconds for it to load completely, during this time is when the UI is locked up... It does eventually load just fine.
Private WithEvents backWork As New BackgroundWorker()
Dim sit As Situation
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnLoad.Click
[code]....
I'm running a program where I call a function which creates a database connection and then runs a stored procedure. I call this function four times from four separate threads. I get an error (Login failed for user 'sa'. The user is not associated with a trusted SQL Server connection.
Exception Source:
.Net SqlClient Data Provider)
when I use multiple threads, but if I have the threads run one after another I have no
[code].....
shove in the right direction on this:My program is setup to instantiate/build five labels at run times, corresponding with those labels five texts boxes are built at run time. The user inputs four numbers into the first four text boxes and then when you click the total button, it totals the four boxes and outputs to the last text box
View 5 RepliesI am creating user accounts in Active Directory via vb.net.Once the account is created I need to assign permissions to the "homedirectory" that I have assigned in Active Directory.I have access to the Active Directory name attributes but I need to convert these to a NT account format ( DOMAINAccountName ) to add security via the DirectorySecurity AddAccessRule method.Is there a way to instantiate the NTAccount class from an Active Directory Entry? I'm not sure if this is necessary I just found that class and it looked like a good fit; a simple routine to create the DOMAINAccountName from the Directory Entry attributes like cn might also suffice.
View 6 RepliesThis question is the follow-up of a a desire to architect a simple spreadsheet API while keeping it user-friendly to those who know Excel well.
To sum it up, this question is related to these below two:
1. How to implement column self-naming from its index?;
2. How to make this custom worksheet initialization faster?.
[Code]...