Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
3.25/5 (4 votes)
See more:
Hello everyone,

I working with MultiListBox but I have a problem

when I select any element in the control, and next step I navigate on my naviBands
the application collapsed and show me an error message.

the image of error is the following:



http://img208.imageshack.us/img208/2898/errormultilistbox1.jpg[^]

"when I navigate from the naviBands the behaviour of MultiListBox is correct, But
when I clicked of any element of MultiListBox and next I navigate again form the naviBand,
then One Error Message Appear.
"

and A part of code that i using is:

string sqlqwery = "select vehiculos.cod as codigo,nombre as Nombre from vehiculos,socio where vehiculos.cod_so=socio.cod order by vehiculos.cod asc;";
DataSet myDs = new DataSet();
conexion con = new conexion();
myDs = con.consulta(sqlqwery);
this.multiColumnListBox1.DataBindings.Clear();
this.multiColumnListBox1.DataSource = myDs.Tables[0];
myDs.Dispose();


Please I need your help

Thanks in advance,

[Modified: just fixed a couple of egregious spelling errors...]
Posted
Updated 26-Jan-11 12:52pm
v2
Comments
dan!sh 27-Jan-11 12:36pm    
1. How it GetItemAt method called?
2. Have you implemented Item.Count property on your own? If yes, please share the code.
3. What is the value of Item.Count?

The error message is same as the one in line above you are showing, hence these questions.
leocode7 27-Jan-11 14:18pm    
I have an answer for your 3third question:
The value of Item.Count before error is 11 (my numbers of registry), but
when the error ocurrs the value od Item.Count is 0.
the row index=-1

the function GetAt Item is:

public object GetItemAt(int rowIndex, int columnIndex)
{
if (DataSource == null)
throw new InvalidOperationException("DataSource Must be set to call GetItemAt()");
else if (Items.Count < 1)
throw new InvalidOperationException("There must be at least one Item in the list to call GetItemAt()");
else if (rowIndex >= Items.Count || rowIndex < 0)
throw new ArgumentOutOfRangeException("rowIndex", rowIndex, "rowIndex must be > 0 and < Items.Count");
else
{
PropertyDescriptorCollection pdc = DataManager.GetItemProperties();
if (columnIndex < 0 || columnIndex >= pdc.Count)
throw new ArgumentOutOfRangeException("columnIndex", columnIndex, "columnIndex must be > 0 and < Items.Count");
else
return pdc[columnIndex].GetValue(Items[rowIndex]);
}
}



any idea??

I don't know of any standard MultiListBox control so I'm assuming its a custom control.

Interesting how the exception is exactly the same message as the else if statement on the line above. I'm guessing the Count property calls the GetItemAt method! and this is causing the problem.

It looks like it is the Count method which is the problem.
 
Share this answer
 
Comments
leocode7 7-Feb-11 1:17am    
the solution is

1) Call begin update method
2) fill the multilistbox with datasource
3) call end update method

like this:

<pre lang="sql">this.multiColumnListBox1.BeginUpdate();
this.multiColumnListBox1.DataSource = myDs.Tables["dt"];
this.multiColumnListBox1.EndUpdate();</pre>
the solution is

1) Call begin update method
2) fill the multilistbox with datasource
3) call end update method

like this:

SQL
this.multiColumnListBox1.BeginUpdate();
                this.multiColumnListBox1.DataSource = myDs.Tables["dt"];
                this.multiColumnListBox1.EndUpdate();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900