Re: Fill a CListCtrl

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



ok, i tried after domodal,
but there is no result. it does not fill the list.
if i place a button om form2 with and add a click event to call insertrow,
it works,

but not from form1.
so the function is ok.





"Jeff Partch [MVP]" <jeffp@xxxxxxxx> schreef in bericht
news:%23EURo9ZnFHA.708@xxxxxxxxxxxxxxxxxxxxxxx
> "N. Karademir" <n.karademir@xxxxxxxxxxxxxxxxxx> wrote in message
> news:uHbxe8XnFHA.2920@xxxxxxxxxxxxxxxxxxxxxxx
>> The code below opens Form2, and adds a row to an CListCtrl.
>> but it does not happen!
>>
>> On form2 the CListCtrl is shown. the columns appear, but no record.
>> the insertrow function does work, i see the messagebox. but no row.
>> maybe the columns are painted after the insertfunction?
>> if so, which event should i use in stead of initdialog?
>>
>>
>>
>> i have form1 with next code:
>>
>> ONBUTTON1
>> {
>> CString a,b,c,d,e,f;
>> string manip.....
>>
>> Overview frmOverview;
>> frmOverview.InsertRow(a ,b,c, d,e);
>> frmOverview.DoModal();
>> }
>
> Maybe it's me, but you call insertrow before DoModal. So it looks like you
> are trying to use the control both before it is created and before it is
> subclassed.
>
>>
>>
>>
>> and form2 with next code
>>
>>
>>
>> BOOL Overview::OnInitDialog()
>> {
>
> Control is created at this point.
>
>> CDialog::OnInitDialog();
>
> Control is subclassed at this point.
>
>> m_List1.InsertColumn( 0,_T("a"),LVCFMT_LEFT,50,-1);
>> m_List1.InsertColumn( 1,_T("b"),LVCFMT_LEFT,120,-1);
>> m_List1.InsertColumn( 2,_T("c"),LVCFMT_LEFT,50,-1);
>> m_List1.InsertColumn( 3,_T("d"),LVCFMT_LEFT,50,-1);
>> m_List1.InsertColumn( 4,_T("e"),LVCFMT_LEFT,70,-1);
>>
>> return TRUE;
>> }
>>
>>
>> void Overview::InsertRow(Cstring COL1,Cstring COL2,Cstring COL3, Cstring
>> COL4, Cstring COL5)
>
> Why does this compile?
>
>> {
>> MessageBox(_T("row will be added"));
>
> MessageBox is not dependant on the control, so it should work.
>
>> m_List1.InsertItem (0,COL1);
>> m_List1.SetItemText(0,1,COL2);
>> m_List1.SetItemText(0,2,COL3);
>> m_List1.SetItemText(0,3,COL4);
>> m_List1.SetItemText(0,4,COL5);
>> }
>
> Why all you calls to m_List1 methods don't ASSERT concerns me.
>
> --
> Jeff Partch [VC++ MVP]
>
>
>


.


Quantcast