October 06, 2022, 10:11:46 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Listview for a large table

Started by Rock Ridge Farm (Larry), September 05, 2006, 11:44:35 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rock Ridge Farm (Larry)

What is the best way to manage a listview for a large database table.
My table has 5000 records and I need to view it with a listview.
I do not want to allocate a structure of 5000 records.
Is there a way to dynamically view data in a listview?

J B Wood (Zumwalt)

You have to probably just use a select of your records and keep track of where you are.
1-100
101-200

etc.

Break it down to groups of 100.
Reset the listview with the new set on a paganation.

Ionic Wind Support Team

That's how I would do it.  You can use DeleteAllItems before adding the next page, and read from the database 100 records at a time.

Ionic Wind Support Team

Rock Ridge Farm (Larry)

That is how I am doing it - just thought there was a better way.

Ionic Wind Support Team

Another way would be to use a scrollbar.  More complicated though.  You still need to come up with the 'glue' code either way.
Ionic Wind Support Team

sapero

A virtual list view is a list-view control that has the LVS_OWNERDATA style. This style enables the control to handle millions of items because the owner receives the burden of managing item data. This allows you to use the virtual list-view control with large databases of information, where specific methods of data access are already in place.
More info
On XP machine i was able to set max 100.000.000 items (using LVM_SETITEMCOUNT)
//#use "xpstyle.res"

// we create a listview database with 10.000.000 items and 8 columns
#define N_ITEMS 10000000
#define N_COLUMNS 8

#define IDC_LV1   1000
#define IDC_ST1   1001
#define IDC_ITEMS 1002
#define IDC_SET   1003

#typedef HWND int;
#typedef LPARAM int;
#typedef COLORREF int;
#typedef DWORD_PTR unsigned int;
#typedef HDC int;

const LVM_SETITEMCOUNT = 0x1000 + 47; // sets the virtual number of items in a virtual list-view control
const LVS_OWNERDATA = 0x1000; // specifies a virtual list-view control
const LVN_GETDISPINFO = -150; // a request to provide information needed to display or sort a list-view item
const LVIF_TEXT = 1;
const NM_CUSTOMDRAW = -12;
const DWL_MSGRESULT = 0;

struct LVITEM {UINT mask;int iItem;int iSubItem;UINT state;UINT stateMask;string* pszText;int cchTextMax;int iImage;LPARAM lParam;int iIndent;int iGroupId;UINT cColumns;UINT *puColumns;}
struct NMLVDISPINFO {NMHDR hdr; LVITEM item;}

import int LvSetItemCount alias SendMessageA(HWND q,int msg,int lp,int wp);
import int cdecl _StrCopyBuf alias strncpy(string *dst,string* src,int max);

class CApp:CDialog
{
declare virtual OnInitDialog();
declare virtual OnSize(int nType,int cx,int cy);
declare virtual OnNotify(int code,int nID,NMHDR *pnmhdr),int; // here you set listview items text
declare virtual OnControl(int nID, int nNotifyCode, unsigned int hControl);
HDC m_lvdrawdc;
}


// note the LVS_OWNERDATA listview style !
global sub main()
{
CApp app;
app.Create(0,0,572+120,329,0x80CF0880,0,"Virtual List-View demo",0);
app.AddControl(CTSTATIC,"",6,5,555,39,0x50000100,0x0,IDC_ST1);
app.AddControl(CTLISTVIEW,"",6,50,556+120,272,0x50010001|LVS_OWNERDATA,0x200,IDC_LV1);
app.AddControl(CTSTATIC,"Items",577,7,29,15,0x5000010B,0x0,656);
app.AddControl(CTEDIT,NumToStr(N_ITEMS),608,5,70,20,0x50812000,0x200,IDC_ITEMS);
app.AddControl(CTDEFBUTTON,"set",584,26,95,22,0x50010000,0x0,IDC_SET);
app.DoModal();
return;
}


/////////////////////////////////////////////
// CApp methods



CApp::OnInitDialog(),int
{
CStatic *s = GetControl(IDC_ST1);
if (s) s->SetText("A virtual list view is a list-view control that has the LVS_OWNERDATA style. This style enables the control " +
"to handle millions of items because the owner receives the burden of managing item data. This allows you to use the virtual " +
"list-view control with large databases of information, where specific methods of data access are already in place");

//setup the virtual listview
CListView *lv = GetControl(IDC_LV1);
if (lv)
{
lv->SetExtendedStyle(ALVS_EX_FULLROWSELECT | ALVS_EX_GRIDLINES);
// first - add columns
for (int col=0; col<N_COLUMNS; col++)
{
dstring columntext[32];
columntext = sprint("column ",col);
lv->InsertColumn(col, columntext, 0, 160);
}
// next - inform the control how many items it should display
LvSetItemCount(lv->m_hwnd, LVM_SETITEMCOUNT, N_ITEMS, 0);
}
}



CApp::OnSize(int nType,int cx,int cy)
{
CListView *lv = GetControl(IDC_LV1);
if (lv) lv->SetSize(6,50, cx-12,cy-56);
}


CApp::OnNotify(int code,int nID,NMHDR *pnmhdr),int
{
if (nID == IDC_LV1)
{
if (code == LVN_GETDISPINFO) // no return value
{
// the listview
if (*(NMLVDISPINFO)pnmhdr.item.mask & LVIF_TEXT)
{
// we create a very simple string. In your database this should be changed :)
dstring itemtext[64];
itemtext = using("this is item # subitem #",*(NMLVDISPINFO)pnmhdr.item.iItem, *(NMLVDISPINFO)pnmhdr.item.iSubItem);
_StrCopyBuf(*(NMLVDISPINFO)pnmhdr.item.pszText, &itemtext, *(NMLVDISPINFO)pnmhdr.item.cchTextMax);
}
}
}
return 0;
}



CApp::OnControl(int nID, int nNotifyCode, unsigned int hControl)
{
if (nID == IDC_SET && nNotifyCode == 0)
{
CListView *lv = GetControl(IDC_LV1);
CEdit     *ed = GetControl(IDC_ITEMS);
if (lv && ed)
{
if !LvSetItemCount(lv->m_hwnd, LVM_SETITEMCOUNT, StrToNum(ed->GetText()), 0)
MessageBox(this, "too many items!","",16);
}
}
}