Strategy to Store / Restore with color background tag of the ListBox contents

I am thinking to Store / Restore Row(s) Background Color(s) in a Window the a ListBox.

Everything works OK, Store in a .sqlite file, Restore from the .sqlite file.

But I have a blank considering the Store / Restore of the Color Tag (name or number or variant is not important).

I Store a Record with the window coordinates (s,x, w,h) and at read time I Restore the Window in the state the user left hie/her session (and I love it).

Any idea ?

While I write this post, I had an idea: add a Column name BgColTag and place my “value” there.

There usually not be many Records (less than 2,500) so another column will not impact the Read / Write performance.

Since that color is an attribute of each record, I store the color in the record. The ListBox has a zero width column that the color gets stuffed into so the PrintCellTag event, in this case, can be used.

Function PaintCellText(g as Graphics, row as Integer, column as Integer, x as Integer, y as Integer) Handles PaintCellText as Boolean  
  Var tmp As String = DataList.CellTextAt(row,DL_ColorColumn)  // the color copied from each record
  If tmp = "" Then
    tmp="&c00000000" 
  End If
  g.ForeColor=Color.FromString(tmp) 
End Function

Thank you Keith,

No, the Color is stored in Row Tag, so I do not have to display its name at ListBox Populated time.

Yes, that the Row Tag can be used to draw the Row.

Time for dinner, I will take a look after it.

Other ideas ?

That would be the best approach. You may have to save it as a string.

When dealing with complex listboxes I generally store a Dictionary in each RowTag or CellTag so that it can contain multiple values that I don’t have to manually parse. A Color attribute could be one of those dictionary elements and it leaves room for future expansion in case you later decide you want to add colors to multiple fields or other invisible data associated with the row.

You can save the Dictionary to one of your sqlite fields with GenerateJSON.

Simple ListBox, but a good idea to remember.

Thank you.