Issue in listing with checkbox

I have a list checkbox… If I click the checkbox the values are displaying in listbox and if uncheck the check box the values are removing default only one value displays in the list always. Kindly let me know the error behind this issue. Thanks in advance.

Use DeleteAllRows instead of RemoveRow ?

Return True at the end of CellClick to make sure that standard listbox functionality doesn’t occur after your logic.

Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) Handles CellClick as Boolean Me.Selected(row) = Not Me.Selected(row) Return True End Function

http://documentation.xojo.com/api/deprecated/listbox.html#listbox-cellclick

@juliaan @Emile Schwarz
Thanks for your reply…
Actually we have a set of data categorized under different group with name (XYX, YZZ …). When i uncheck one group name, one row continue to remains in the listbox. this issue is there in all the groups This is how our code is… (for group name XYX)

  For i = 0 To DataList.ListCount - 1
    DataList.CellState(i, 0) = Checkbox.CheckedStates.Checked
    if Checkbox4.State = CheckBox.CheckedStates.Unchecked Then
      if DataList.Cell(i,2) ="XYX" Then
        datalist.RemoveRow(i)
      End if
    End if
  Next

@Emile Schwarz If i use DeleteAllRows i think its will delete the entire list. Right?

A sample project would be really helpful here instead of gradually giving more details as people ask questions.

It might be best to upload a simple project showing the problem and explaining what you’re trying to achieve.

Yes.

@Emile Schwarz the actual concepts is we are having five groups with checkbox and the label name as group names with checkboxes. If we click the first checkbox the first group name datas will be displayed in the datalist the issue what we have faced is if we uncheck means not all group name datas is removed from the list for eg if the group name consists of five records means only four removed from the datalist, the one will not be removed from the datalist.

Listbox first Row # is 0, not 1. Check how you remove a Row (are-you using a Loop to achieve that ?)…

@Emile Schwarz I am using this one as a loop starting point For i=0 to datalist. Count -1

When removing rows, you should start at the end of the list. Like this, For I = datalist.Count - 1 downto 0

Aldrin:
your answr is the reason why Greg and Julian ask to see the used code. Guessing or betting is a bad game and needs tons of Q&A.

I may have found the error, but if so, it is a pure luck (and in that case, I am absolutely stoned, this is unusual for me). :wink:

To further explain why, when you remove a row, all the other rows move down one index value. So if you remove row 1, row 2 becomes the new row1. But the next time through the loop, the index is 2, so you have skipped examining the old row 2, as it is now in the row 1 position.

When you remove rows from a listbox or array, always start at the end and move toward the beginning.

Worst: how to remove Rows based on a certain Row behavior (a.k.a. non continguous Rows) ?

At Row addition (AddRow, InsertRow, AddFolder, InsertFolder), add a special value in RowTag. Then, if you want to delete Rows following a certain Tag value, it is easy: follow the above advice (from last Row to Row 0) and check the RowTag value: if they meet the criteria, delete it, else check the next one.

Of course, if your question is scarce in details, no one can suggest a good answer (or a far better answer, even a creative answer) :wink: