Priority level on weblistbox

I am practicing my programming for fun. I am doing my web project. Right now, I am trying to figure out how to add +1 to the row for “Urgent” - top level and lowest level - “non-urgent” on a weblistbox. I know it is Web 2.0. it can be a different code.

Here’s my program for the populatelistbox:

select case rs.ColumnAt(7).StringValue
case “Urgent”
dataList.CellTextAt(dataList.LastAddedRowIndex, 7) = rs.ColumnAt(7).StringValue
index = index+1
case “T1-Today”
dataList.CellTextAt(dataList.LastAddedRowIndex, 7) = “Today”
index = index+index+1
case “T2-Tonight”
dataList.CellTextAt(dataList.LastAddedRowIndex, 7) = “Tonight”
index = index+index+index+1
case “T3-Tomorrow”
dataList.CellTextAt(dataList.LastAddedRowIndex, 7) = “Tomorrow”
index = index+index+index+index+1
case “T4-ThisWeek”
dataList.CellTextAt(dataList.LastAddedRowIndex, 7) = “This Week”
index = index+index+index+index+index+1
case “T5-Weekend”
dataList.CellTextAt(dataList.LastAddedRowIndex, 7) = “Weekend”
index = index+index+index+index+index+index+1
case “T6-NextWeek”
dataList.CellTextAt(dataList.LastAddedRowIndex, 7) = “Next Week”
index = index+index+index+index+index+index+index+1
case “OnHold”
dataList.CellTextAt(dataList.LastAddedRowIndex, 7) = “On Hold”
index = index+index+index+index+index+index+index+index+1
end select
end if

Did you notice that I wrote index = … … …, the next can be missing one. Can it be added to weblistbox.rowcount or lastrowindex? Welcome here for a solution. Thanks.

What are you doing with the index and why that lovely formula?

1 Like

Like a sorting. Urgent should stay on top of the row. It is a category. If I want a work order from urgent to tomorrow, the row should move down. Um…think of a first row for urgent, tomorrow is the fourth row. As you see the index acts as the row, it adds up until the fourth row. Every time a new job comes up, we set the priority on those and go to it. Make sense?

Yes, I have something similar for a desktop listbox. Does the weblistbox have a compare rows event?

This is a custom order for a desktop listbox where email clients are sorted before imap accounts. The original values are in the row tag:

dim AccountDictionary1 as Dictionary = Dictionary(me.RowTagAt(row1))
dim AccountDictionary2 as Dictionary = Dictionary(me.RowTagAt(row2))

if not AccountDictionary1.HasKey("isIMAP") or not AccountDictionary1.HasKey("AccountName") then break

dim Account1, Account2 as String
if AccountDictionary1.Value("isIMAP").BooleanValue then
  Account1 = "b-" + AccountDictionary1.Value("AccountName")
Else
  Account1 = "a-" + AccountDictionary1.Value("AccountName")
end if
if AccountDictionary2.Value("isIMAP").BooleanValue then
  Account2 = "b-" + AccountDictionary2.Value("AccountName")
Else
  Account2 = "a-" + AccountDictionary2.Value("AccountName")
end if

dim theSorter as new NaturalSortComparator
result = theSorter.Compare(Account1, Account2)

Return True // Use the custom sort
1 Like

No it doesn’t.

You can have a column with a number in it (priority or so)
then use ColumnSortDirectionAt and ColumnSortTypeAt to have the list be sorted.

If I understand, you read data from database and want it to be displayed sorted in Listbox.
Then you should use “order by” in your sql server.
For mysql this could be something like:

SELECT * FROM mytable ORDER BY FIELD(nameOfColumn7, 'Urgent', 'T1-Today', 'T2-Tonight'. 'T3-Tomorrow')

Or in Sqlite it should be something like:

ORDER BY CASE nameOfColum7 WHEN ‘URGENT’ THEN 0 WHEN ‘T1-Today’ THEN 1 WHEN ‘T2-Tonight’ THEN 2 WHEN ‘T3-Tomorrow’ THEN 3 END

Or, and should be “nicer”, add a column named “sort” to your database and set URGENT Rows to 0, T1-Today to 1 etc.
then you can easily sort with that column.

In this cases you get the sorted data from the database and do not have to sort it when inserting into listbox.

Yes - in fact when I need to order a DesktopListbox by a different column, by clicking in the correct part of the header, I don’t bother with the Listbox’s sorting ability. I just reload the whole listbox from the SQLite database, uisng the appropriate ORDER BY.

It works but I will check I can add one more column, job name by alphabetical

Ok, it won’t work. It needs to separate for SQLite ORDER BY for job names alphabetically and the priority remains unchanged.

ORDER BY CASE nameOfColum7WHEN ‘URGENT’ THEN 0 WHEN ‘T1-Today’ THEN 1 WHEN ‘T2-Tonight’ THEN 2 WHEN ‘T3-Tomorrow’ THEN 3 END,Job_Name’`

will do that

Oh Yay! It does work. Thanks, Marius!