ARTICLE

Editable ListBox in C#

Posted by Gautam Shrestha Articles | Windows Controls C# June 09, 2005
The attached sample code demonstrates how you can create an editable ListBox control, which will let you edit ListBox items at runtime.
Reader Level:
Download Files:
 

Suppose you need to edit an item in a list box (it is read-only list of item) at a runtime. This sample code demonstrate a simple approach to create an editable listbox.

ListBox.gif

To edit an item in a list box, all you need is one hidden text box. Keep textbox hidden of set property visible as false and show it whenever you required.

Login to add your contents and source code to this article
post comment
     

Very good concept used What caught ma attention was your logic applied in these lines : Rectangle r=this.listBox1.GetItemRectangle(itemSelected); this.textBox1.Location=new System.Drawing.Point(r.X+5,r.Y+5); this.textBox1.Size=new System.Drawing.Size(r.Width+4 , r.Height-10); this.textBox1.Visible=true; this.textBox1.Text=itemText; this.textBox1.Focus(); this.textBox1.SelectAll(); Very nice Mr. Gautam. Thank You for teaching me this beautiful concept.

Posted by Manoj Singh Panwar Dec 03, 2011

Dear Gautam it's really helpful to us but you should write some description about your article it may become more effective thanks.

Posted by Amit Maheshwari Dec 03, 2011

Very Good Code

Posted by Sanjay Tripathi Jun 19, 2009

Well you're assigning rather than comapring

Posted by Lasse Jaervensivu Jul 17, 2007

Hello gautam shrestha'

Plese tell me quick!

In c#(ASP.net) The concept is items are added to a list box from a TextBox. if the item is already appear inside the list box it shows Already exist otherwise it can be added. I had written the following query for that.

if(ListBox1.Items.Contains(TextBox1.Text)=True))

{

Response.Write("Already Exists");

}

else

{

ListBox1.Items.Add(TextBox1.Text)

}

But the above query doesn't worked. What is the reason Pls tell me quick otherwise I will became a mad!!!!!!!

Posted by santhanam krishnan Oct 28, 2006
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts