none
TreeView中怎么禁止选中的TreeNode的ImageIndex变为默认的TreeView->SelectedImageIndex RRS feed

  • 问题

  • 代码:

     

    public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: 在此处添加构造函数代码
    			//
    			treeView1->CheckBoxes = true;
    
    			ImageList^ imageList = gcnew ImageList;
    			imageList->Images->Add( Bitmap::FromFile( "0.jpg" ) );
    			imageList->Images->Add( Bitmap::FromFile( "1.jpg" ) );
    
    			treeView1->ImageList = imageList;
    			
    			//treeView1->NodeMouseClick+=gcnew TreeNodeMouseClickEventHandler(this,&Form1::treeView1_NodeMouseClick);
    
    
    			TreeNode^ node;
    			for ( int x = 0; x < 3; ++x )
    			{
    				node = treeView1->Nodes->Add("Hello " +x*4);
    				for ( int y = 1; y < 4; ++y )
    				{
    					node = node->Nodes->Add( "Hello "+(x * 4 + y));
    					node->ImageIndex=y%2;
    				}
    
    			}
    		}
    	private: void treeView1_NodeMouseClick(Object^ sender,TreeNodeMouseClickEventArgs^ e)
    			 {
    				 MessageBox::Show("it changed to default!");
    			 }
    
    	protected:
    		/// <summary>
    		/// 清理所有正在使用的资源。
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::TreeView^ treeView1;
    	protected: 
    
    	private:
    		/// <summary>
    		/// 必需的设计器变量。
    		/// </summary>
    		System::ComponentModel::Container ^components;
    
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// 设计器支持所需的方法 - 不要
    		/// 使用代码编辑器修改此方法的内容。
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->treeView1 = (gcnew System::Windows::Forms::TreeView());
    			this->SuspendLayout();
    			// 
    			// treeView1
    			// 
    			this->treeView1->Location = System::Drawing::Point(24, 27);
    			this->treeView1->Name = L"treeView1";
    			this->treeView1->Size = System::Drawing::Size(244, 203);
    			this->treeView1->TabIndex = 0;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->treeView1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    	};
    

     

    当选中imageIndex=1的node,其图标变为imageindex=0的。

     

    怎么取消掉这种变化,而当选中node时,其图标不变。

     

     



    2011年7月7日 2:21

答案