.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

ListBox in Forms application

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :Windows Application


In my forms application, I want to use a ListBox.
For example:

string name = TextBox1.Text;
string address = TextBox2.Text;
string city = listBox1.SelectedValue.ToString();

I have added several options to the listbox but when I start / debug the program and I select an option in the listbox, it doesn't work. I think I miss something here.

What's the right way to use a ListBox in my form ?



View Complete Post

More Related Resource Links

Application Architecture in Windows Forms 2.0

Applications have special support in Windows Forms. For starters, you can manage and tailor your application's lifetime, and, when the work flow is disrupted by an unhandled exception, you can choose from several methods of response. Then, there are several application models that you can employ, including Single Document Interface (SDI) and Multiple Document Interface (MDI) applications, each of which can support either multiple-instance or single-instance mode, the former the VS05 default and the latter requiring special consideration. All applications, however, can discover and use a wide variety of information about the system and environment they execute in.

Application Architecture in Windows Forms 2.0-Single-MDI Applications

Consider an MDI application like Microsoft Excel; files opened from the file system (by double-clicking) are all opened as separate child windows within the parent Excel window.7 For the first instance of an MDI application to open a new child window to display the file that was passed to the second instance of the application, the second instance must be able to communicate with the initial instance.

.NET Internals: Tailor Your Application by Building a Custom Forms Designer with .NET


The design-time architecture of Windows Forms in the .NET Framework has made development much more flexible than it had been with MFC. With Windows Forms, you can drag one of your custom controls from the toolbox and drop it onto the Visual Studio design surface and even though Windows Forms knows nothing about the control, it's able to host it and let you manipulate its properties-not possible in MFC. In this article, the author discusses what's going on under the covers as you design your forms and then walks through the creation of a bare-bones forms designer.

Sayed Y. Hashimi

MSDN Magazine December 2004

Windows Forms: Give Your .NET-based Application a Fast and Responsive UI with Multiple Threads


If your application performs any non-UI processing on the thread that controls the user interface, it may make the app seem slow and sluggish, frustrating users. But writing multithreaded apps for Windows has long been restricted to C++ developers. Now with the .NET Framework, you can take advantage of multiple threads in C# to control the flow of instructions in your programs and isolate the UI thread for a fast and snappy user interface. This article shows you how. Also, it discusses the pitfalls of multiple threads and presents a framework for safe concurrent thread execution.

Ian Griffiths

MSDN Magazine February 2003

Forms Based Authentication on Extranet Application

I have a web application that is using classic authentication. I have extended it to my extranet so I can use https from the outside. All of this works, except I would like to have the extranet users not have to type domain\username. I am guessing I need to use claims based authentication with forms. It seems the only way to do this, would be to go back in time, and tell my original application to use claims based instead of windows. Is there a way I could have just my extended site use forms? I would really like to keep my extranet users out of active directory, as they are not part of my company.

How to add Sharepoint dll reference to Windows Forms application project in Visual Studio 2010?

Hi,I am using Windows Forms application template in Visual Studio 2010 Beta. I created this for some R & D work. Now I am using Sharepoint object model in application. When I am trying to add Sharepoint dll reference from .NET tab, I can not see Windows Sharepoint Services there Which was available in Visual Studio 2005.Also If I am add this sharepoint dll from ISAPI folder (14 Hive), it is added succesfully, but it is not taking actually in project and showing me an error during running mode that theError 12 The type or namespace name 'SharePoint' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) Please suggest me how to add Sharepoint dll reference in Windows forms application in Visual Studio 2010?

Windows Forms application Stopped Working message in Windows Vista



A Windows Forms application developed with VB2008 Express that has been successfully run on two Windows XP systems and a Windows 7 system fails to run on two of two Windows Vista systems tried so far.


Attempting to run the app on a Windows Vista system results in a system dialog box titled, Microsoft Windows, with the message, A problem caused the program to stop working correctly.  Windows will close the program and notify you if a solution is available.  A single button at the lower right of the dialog contains the text, Close Program.
The initial form of the application never displayed and the dialog above appeared with little delay after attempting to start the program.

The program uses an SQL Server Compact Edition 3.5 database and the program is compiled to include the following .DLL files so the user does not need to install SQL ServerCE.

The Load event of the initial form causes a DataSet to be filled from the SQL CE DB.

I have the System Informa

I need a dynamic connection string for my windows forms application.


Hello folks


I am brand new to forms applications and visual studio 2008 I am building a forms application to connect to a 3rd party's sdf file. There is no password or username required to connect however the 3rd party app installs the sdf in the users folder for me I am on windows 7 but I have clients on xp.


I went to add a data connection and chose sql ce file and browsed out to my location and it connects and works. But I need this connection string to be for whoever is logged into there laptops or computers no matter the operating system version xp,vista,7.


Data Source=C:\User\username\AppData\Roaming\PS\GES\surve.sdf


Can someone tell me how to do that. Also please explain in words a new borne could understand cause like I said I am new to this.


Thank you


System.Windows.Forms.ListBox scroll-to-top on focus - how can I prevent this behavior?




I've been trying to find a solution online for the last couple days and I'm surprised at how little there is on this topic -- namely, I'm trying to prevent the default behavior of ListBoxes scrolling to the top whenever they regain focus.


I've created a toolbar-like control that is docked on the left-hand side of my screen.  This vertical toolbar is comprised of several ListBoxes, and each ListBox is collapsible (much like the Visual Studio designer toolbar).  The problem is, if I click on an item on a ListBox that is partially off the top of the screen, the entire toolbar scrolls so that the first item in that particular ListBox is at the top, so your mouse is no longer over the item you originally wished to select.


I'm trying to figure out a way to prevent this behavior.  Any suggestions?



How to make the windows forms application install only 1 time and be used only 1 time only



I have a need to create an applicaiton that can be installed 1 time only be a user. The application can also be used only 1 time. (on a given PC)

The user may or may not be and administrator.

How can I do this (without registry alteration if possible)?

Thanks much.


Best Practices for elevating permissions in a Win Forms Application



Here is the situation.  I am working to create a windows forms application which allows various help desk personnel to view active directory and powercampus (a sql db) data for users.  The program must also be able to reset users passwords.  It will be installed on multiple desktop machines on our network.

This requires a certain level of permissions which we do not want to give to the Active Directory accounts of the personnel who will use it.

My working solution in this case is to create an Active Directory account for the application, give that account the necessary permissions and then have the application impersonate this account when it needs elevated permissions.  I'm using advapi32.dll-LogonUser.  The username and password for the account are hard coded into the program.

My question is, how do i do this better?  Is there some other way to give the application elevated permissions without giving those permissions to the users.  Is there a better way to impersonate an active directory account.  Last, i know that hard coding the username and password is not very secure.  I would prefer to encrypt the information somehow, but then the program must have the key to decrypt, which is only 1 step removed from what i have now.  how can i safely and simply encrypt the account password?


SQL Server 2005 random login failures for windows forms application


One of our VS .NET 2008 windows forms applications runs from multiple client machines. The application randomly has login failures from random machines and from random places in the code. The login works almost every time but about once every fifteen minutes an error shows up in SQL Server error logs from a random user. We are running a clustered SQL Server 2005 system and the database is in 2005 (90) mode.

The following error appears in the SQL Server error logs:

Login failed for 'App_Login'. [CLIENT: XXX.XXX.X.XXX] Error: 18456, Severity: 14, State: 16.

The following error is what the client sees:

How to hide SQL Server password from user in an Windows Forms Application?


Using - VS 2005, SQL Server 2005 Express, Windows Forms Application


I am unable to find a way that hides the password to connect to database in case of a Windws Forms Application.

- app.config is accessible to the user, so connection strings an be read.

- app.config can't be encrypted as in case of ASP.NET applications

- hardcoding the password in the application in connectionstring still makes it possible to be discovered by a user

Vibhor Agarwal

Move items from one listbox to another listbox in C# windows application.


Hi, I have two listbox controls. I have to move the selected items from first list box to second list box and vice versa. Also i have to move all the items from listbox1 to listbox2 and vice versa. . The listbox box is already assigned the datasource property. The datasource for both list box is dataset. Please help in solving this issue.


Thanks in advance


Assuming identity of other logged in users in web application using Forms Authentication and Singlet



I have a web application with a login form. A user enters a user name and password. If they exist in the database the user is authenticated using these two lines:

FormsAuthentication.SetAuthCookie(userName, false);
FormsAuthentication.RedirectFromLoginPage(userName, false);

The problem is that when a user logs in at first he is logged in as himself. When navigating on the web application for a while the user assumes the identity of another logged in user. This happens all the time.

In my web.config the authentication mode looks like this:

<authentication mode="Forms">
  <forms loginUrl="LogOn.aspx" name=".ASPXFORMSAUTH">
  <deny users="?" />

The site does not use ASP.NET session variables. Instead each page initializes a Singleton class, which stores itself in a static class variable, always accessing the users data already read from the database.

The Singleton implementation is:

static readonly WebSession instance = new WebSession();


public static WebSession GetSingletonInstance
  get { return instance; }

Could the problem with assuming anoth

Profiling Question for Widnows Forms Application



I am profiling a windows forms application using ANTS profiler.

One of the forms has got many user controls and it takes time to create these user controls.

The pro filer shows the following line taking around 700ms for the first control.

        private System.ComponentModel.IContainer components = null;

The subsequent ones takes lesser time for executing this line, but still the last one take 200 ms.

This is affecting my start up time.

Is there any workqroung to make it faster?



how to develop forms (desktop database) application in shortest time ?



I am new to WinForms and want to develop a small database application. Initially I am not much keep on performance. Please advice me some way (may be automaticed) to develop in very short time.

I am doing the following things.

1. Login

2. Adding/ editing/ deleting records in db.

3. Adding/ editing / deleting sales from grid.

4. some reports.

Thanks for guiding & helping me.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend