Thread: Maybe a weird question

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > Thanks but I already got it to work.
    Care to share?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #17
    Registered User
    Join Date
    Aug 2006
    Location
    Slovenia
    Posts
    12
    Sorry I thought nobody wanted to see my crummy code.

    I narrowed it down to only three columns to search for. Other were nonsense anyway.

    Look and be amazed!
    (translated for easier undestanding)

    Code:
    void CVaja6ListControlDlg::OnBtnFind() 
    {
    	// clean the list of previously selected items
    	int i=0;
    	while(i<m_cMyList.GetItemCount()) 
    	{
    		m_cMyList.SetItemState(i, 0, LVIS_SELECTED); 
    		i++;
    	}
    
    	UpdateData(); 
    
    	CString readName;
    	CString readSurname;
    	CString readAge;
    	
    	int numberChecks=3; // let's say all three check boxes were selected
    	// then we substract 1 if it was not checked 
    	// if not checked we set some nonsense so there won't be a hit
    	if(!(m_chkByName))	
    		{ m_name="ihopeyoudidntinputthis"; numberChecks--; }  
    	if(!(m_chkBySurname))
    		{ m_surname="ihopeyoudidntinputthis"; numberChecks--; }
    	if(!(m_chkByAge))
    		{ m_age=9545; numberChecks--; }
    
    	
    	// if no checboxes were checked we exit otherwise everything will be a hit
    	if(numberChecks==0) { return; } 
    
    	int hits; // number of hits, if this equals numberChecks we have a complete hit
    
    	i=0;
    	m_cMyList.SetFocus(); // focus on listctrl so we can select
    	while(i<m_cMyList.GetItemCount())
    	{ 
    		hits=0;
    		readName = m_cMyList.GetItemText(i,0);	// read from CListCtrl
    		readSurname = m_cMyList.GetItemText(i,1);
    		readAge = m_cMyList.GetItemText(i,2);
    		
    		// compare what we read from CListCtrl with what was put into the edit boxes to search for
    		if(strcmp(readName,m_name)==0)	
    			{ hits++; }
    		if(strcmp(readSurname,m_surname)==0)
    			{ hits++; }
    		CString strStarost;
    		strStarost.Format("%i", m_age);	
    		if(strcmp(readAge,strStarost)==0)
    			{ hits++; }
    
    		if(numberChecks==hits) // if we have a complete hit
    		{
    			m_cMyList.SetItemState(i, LVIS_SELECTED, 0xFF);
    		}
    		i++;
    	}
    	// here I should scrool the list down to the last record found, but how??
    }
    Last edited by MarkookraM; 08-25-2006 at 12:18 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A weird question.
    By IanKoro in forum C Programming
    Replies: 19
    Last Post: 06-08-2009, 12:00 PM
  2. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Weird Question maybe
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 12-27-2001, 07:30 PM