The Single or Stand-alone table (part 4)
Welcome Back!
Hopefully you are hanging in there. I know this is a lot of information to absorb. As we move forward things will begin to click. I'm going to skip over the ListView Gadget as it is identical to the ComboBox except that instead of ComboBox were using the ListView Gadget instead. I'll go ahead and post the code for you to review, but then we'll move onto the ListIconView Gadget.
Procedure LoadListViewName(lvData.i)
Protected DBID, Sql$
ClearGadgeItems(lvData)
DBID = DB::Open(DBTYPE::#Sqlite)
Sql$ = " Select "
Sql$ = Sql$ + " ID, "
Sql$ = Sql$ + " Name "
Sql$ = Sql$ + " FROM "
Sql$ = Sql$ + " FighterSize "
Sql$ = Sql$ + " ORDER BY "
Sql$ = Sql$ + " Name "
If DB::Query(DBID, Sql$)
While NextDatabaseRow(DBID)
AddGadgetItem(lvData, -1, GetDatabaseString(DBID,DatabaseColumnIndex(DBID,"Name")))
SetGadgetItemData(lvData, ComboBoxEx::CountItems(lvData)-1, GetDatabaseLong(DBID, DatabaseColumnIndex(DBID,"ID")))
Wend
EndIf
DB::Close(DBID)
EndProcedure
Now we will turn our attention to the ListIconView Load. In my development it is very rare for a table not to have a ListIconView Gadget. In my design/development process I design my screens First. As I think through the flow of the4 screens I find I hit about 80% of the fields I eventually end up with. So, knowing this ahead of time I never try and build in the columns of the ListIconView, I know it will always change. I put the columns into the ListIconView here in the Module.
As before I do not use the "standard" PureBasic ListIconView Gadget, Once again favoring Thorsten Hoeppner's custom ListEx Gadget instead.
Let's begin the code review of the ListIconView; Below is the entire Code block for your review. As before, I'll walk my way through this below.
Procedure LoadListIcon(liData.i)
Protected DBID, Sql$
Protected Result
DBID = DB::Open(DBTYPE::#Sqlite)
ListEx::DisableReDraw(liData, #True)
ListEx::ClearItems(liData)
ListEx::RemoveColumn(liData, 0) ;Name
;===== Build Column Titles =====-
ListEx::AddColumn(liData, 0, "Name", 60)
ListEx::SetColumnAttribute(liData, 0, ListEx::#Align, ListEx::#Left)
Sql$ = " Select "
Sql$ = Sql$ + "Name, "
Sql$ = Sql$ + "ID "
Sql$ = Sql$ + "FROM "
Sql$ = Sql$ + "FighterSize "
Sql$ = Sql$ + "ORDER BY "
Sql$ = Sql$ + "Name "
;===== Populate Data Into Column =====
Result = DB::Query(DBID, Sql$)
If Result > 0
While NextDatabaseRow(DBID)
ListEx::AddItem(liData, -1,GetDatabaseString(DBID, DatabaseColumnIndex(DBID,"Name")) + #LF$ )
ListEx::SetItemData(liData, ListEx::CountItems(liData) -1 , GetDatabaseLong(DBID, DatabaseColumnIndex(DBID,"ID")) )
Wend
EndIf
DB::Close(DBID)
ListEx::DisableReDraw(liData, #False)
EndProcedure
As we have seen before the Procedure constructor receives in the Handle of the ListIconView Gadget. I then make the call to our DB Module to Open the database. The next steps are to clear Rows and columns of the Gadget, then we build the desired columns, set each column's alignment and size.
Then we build out SQL Query and calling our DB Module again Execute the query against the database.
Next, we iterate through the resulting record set and load the ListIconView with the necessary fields, separated by #LF$, from our query.
Finally, we once again call our DB Module to Close our Database.
Comments
Post a Comment