www.pudn.com > TreeAndList.rar > TreeAndListView.cpp
// TreeAndListView.cpp : implementation of the CTreeAndListView class
//
#include "stdafx.h"
#include "TreeAndList.h"
#include "TreeAndListDoc.h"
#include "TreeAndListView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTreeAndListView
IMPLEMENT_DYNCREATE(CTreeAndListView, CListView)
BEGIN_MESSAGE_MAP(CTreeAndListView, CListView)
//{{AFX_MSG_MAP(CTreeAndListView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTreeAndListView construction/destruction
CTreeAndListView::CTreeAndListView()
{
// TODO: add construction code here
}
CTreeAndListView::~CTreeAndListView()
{
}
BOOL CTreeAndListView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTreeAndListView drawing
void CTreeAndListView::OnDraw(CDC* pDC)
{
CTreeAndListDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CTreeAndListView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
//listview来显示数据
CListView::OnInitialUpdate();
CListCtrl &listCtrl=(CListCtrl&)GetListCtrl();
listCtrl.ModifyStyle (0,LVS_REPORT);
listCtrl.ModifyStyle (LVS_EDITLABELS,0);//禁止修改列标题
listCtrl.SetExtendedStyle (LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE|LVS_EX_INFOTIP|LVS_EX_SUBITEMIMAGES|LVS_EX_GRIDLINES);
listCtrl.InsertColumn (0,"操作员姓名",LVCFMT_LEFT,100);
listCtrl.InsertColumn (1,"操作员住址",LVCFMT_LEFT,100);
listCtrl.InsertColumn (2,"操作员联系电话",LVCFMT_LEFT,150);
listCtrl.InsertColumn (3,"测试",LVCFMT_LEFT,150);
}
/////////////////////////////////////////////////////////////////////////////
// CTreeAndListView printing
BOOL CTreeAndListView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTreeAndListView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTreeAndListView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTreeAndListView diagnostics
#ifdef _DEBUG
void CTreeAndListView::AssertValid() const
{
CListView::AssertValid();
}
void CTreeAndListView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CTreeAndListDoc* CTreeAndListView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTreeAndListDoc)));
return (CTreeAndListDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTreeAndListView message handlers
//更改自己的值。
void CTreeAndListView::changeDataFromTreeViewOnClick(CString strInfo)
{
CListCtrl &listCtrl=(CListCtrl&)GetListCtrl();
if (strInfo == "商品入库")
{
listCtrl.DeleteAllItems();
listCtrl.InsertItem(0, "李长林");
listCtrl.SetItemText(0, 2, "2345678"); //坐标为行列 即0行2列
listCtrl.SetItemText(0, 3, "test");
listCtrl.InsertItem(1, "李长林1"); //插入第二行
listCtrl.SetItemText(1, 1, "长江大学1");
listCtrl.SetItemText(1, 2, "23456781");
listCtrl.SetItemText(1, 3, "test1");
listCtrl.SetItemText(0, 1, "长江大学");
}
if (strInfo == "商品信息管理")
{
listCtrl.DeleteAllItems();
listCtrl.InsertItem(0, "桔子");
listCtrl.SetItemText(0, 1, "好东西");
listCtrl.SetItemText(0, 2, "8833456");
}
}