473,394 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

C#NET2008 Problem Refill Listbox

126 100+
Hullo Good Guys,
I need your help. Please help me.

I am trying to reload the Listbox1 with new data contained in DataSet. I am vey confused as this error was generated :
Items collection cannot be modified when the DataSource property is set.

This is the coding that generate the error:
this.listBox1.Items.Clear();

Here are the Overall coding:
Expand|Select|Wrap|Line Numbers
  1.  private void FLoadListBox(string strTagName)
  2.  {  
  3.    this.listBox1.Items.Clear();  <--- error 
  4.  
  5.    if (this.txtInput.text == "Product")
  6.      {
  7.        string strSql = "Select Product from TblSales";
  8.      }               
  9.  
  10.    else
  11.     {
  12.       string strSql = "Select Orders from TblSales";
  13.     }
  14.  
  15.     sqlconn = new SqlConnection(connstr);
  16.     sqlconn.Open();
  17.  SqlDataAdapter DA = new SqlDataAdapter(strSql, sqlconn);
  18.    System.Data.DataSet DS = new DataSet("DS");
  19.    DS.Clear();
  20.    DS.Tables.Clear();                  
  21.    DA.Fill(DS, "Display");          
  22.  
  23.   if (this.txtInput.text == "Product")
  24.     {
  25.          this.listBox1.DisplayMember ="Product";
  26.      this.listBox1.DataSource = DS.Tables["Display"];
  27.     }  
  28.   else
  29.     {
  30.      this.listBox1.DisplayMember ="Orders";
  31.      this.listBox1.DataSource = DS.Tables["Display"];
  32.     }
  33.  
  34.     sqlconn.close();
  35.   }
  36.  
  37.  
Dec 6 '10 #1
0 1201

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: R.Wieser | last post by:
Hello All, I'm trying to get a "Virtual Listbox" to work. I've currently got a form, and used CreateWindowExA to create a ListBox with the LBS_OWNERDRAWFIXED and LBS_NODATA flags on it. I've...
2
by: Petter L | last post by:
I have set up a test program on how to use colletions saved and loaded from a file. It was a part of a other program until this happends. The saving process working fine but it looks like something...
2
by: Steve Potter | last post by:
I am trying to find some method of attaching a Listbox object to a list object so as the contents of the list are changed the contents of the Listbox will be updated to match. I have found a few...
0
by: Marc | last post by:
Hello, I have converted a project from .NET2005 to .NET2008 RTM I have also converted the project to use .NET Framework3.5 (as the project will only be in Beta in a few month). My project is...
2
by: lenniekuah | last post by:
Hullo Good Friends, I need your help. Please help me. I am using C#NET2008 to develop Window application I am trying to retrieve Sales Transaction and print it on WORD Document as statement...
2
by: lenniekuah | last post by:
Hullo Good Friends, I need your help again, please help me. I am using C#NET2008 for Window Application. Being requested to use ListBox to display 2 columns of data, i.e. OrderNumber, ...
9
by: lenniekuah | last post by:
Hullo Good Guys, I need your help. I am very puzzled about using WITH with C#NET2008. The coding below when used in VB.NET I will be using WITH : Wth me.ListBoxCust .ColumnWidth =...
1
by: Lennie Kuah | last post by:
Hi Good Guys, I need your help. Please help me. I am using C#NET2008 and Window Application to print Customer Order Transactio onto Microsoft WORD 2003 document. This is the expect result on...
1
by: lenniekuah | last post by:
Hullo Good Friends, I need your help, Please Help me. I am using C#Net2008 to develop Window Application. I have not create ARRAY before. The Project Manager asked me to use ARRAY to contain...
2
by: lenniekuah | last post by:
Hullo Good Friends, I am back again seeking help. Please help me. I am using C#NET2008 Window Application, This is the situation. Should either one of this control, txtXMLFolder.Text ,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.