Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. DataGridView multiline selection without ctrl key

DataGridView multiline selection without ctrl key

Scheduled Pinned Locked Moved Managed C++/CLI
helpdatabasedotnetgraphicssecurity
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andreoli Carlo
    wrote on last edited by
    #1

    Actually what i'm trying to do is to get a multiline rows selection without the problem of holding the ctrl key (i'm developing a touchscrenn app). By now i quite get it with a list of selected lines, but if i try to click fast on the rows it give me some painting error. Can someone give me a hint. (Maybe i should fire the ctrl command? i don't know how to simulate the pressdown command :( )

    #ifndef _CSTDGV_
    #define _CSTDGV_

    namespace primoAlpha {

    using namespace System;
    using namespace System::Drawing;
    using namespace System::Windows::Forms;
    using namespace System::Security::Permissions;
    
    /\*\*
     \* Classe per la gestione di un DataGridView personalizzato
     \* per una gestione tramite delegate del riordinamento delle colonne
     \* e per permettere di selezionare multiline senza il tasto control premuto
     \* 
     \* @author      Carlo Andreoli
     \* @version     0.1.0, 24/07/09 -- Prima versione (beta)
     \*/
    public ref class personalDataGridView : DataGridView
    {	
    public:
    
    	/\*\*
    	 \* Costruttore dove inizializzo le variabili che estendono la classe base
    	 \* 
    	 \* @author      Carlo Andreoli
    	 \* @version     0.1.0, 24/07/09 -- Prima versione (beta)
    	\*/
    	personalDataGridView()
    	{
    		this->selectedRowIndexes=gcnew Collections::ArrayList();
    		this->MultiSelectForced=false;
    	}
    	
    	/\*\*
    	\* variabile per gestire i selected senza il control selezionato
    	\*/
    	property bool MultiSelectForced
    	{
    		bool get() {
    			return \_MultiSelectForced;
    		} 
    		void set(bool value) {
    			this->\_MultiSelectForced = value;
    			this->selectedRowIndexes->Clear();
    			processSelectedRowIndexes();
    		}
    	}
    protected:
    	/\*\*
    	 \* override sulla funzione che gestisce CurrentCellChanged 
    	 \* per gestire il multiselect senza il tasto del ctr schiacciato
    	 \* @param		e
    	 \* 
    	 \* @author      Carlo Andreoli
    	 \* @version     0.1.0, 24/07/09 -- Prima versione (beta)
    	\*/
    	virtual void OnCurrentCellChanged (EventArgs^ e) override
    	{
    		if (this->CurrentRow!=nullptr && \_MultiSelectForced) {
    			int act\_row=this->CurrentRow->Index;
    		
    			if (selectedRowIndexes->Contains(act\_row)) {
    				selectedRowIndexes->Remove(act\_row);
    			}
    			else selectedRowIndexes->Add(act\_row);
    
    			//ora vado ad indicare i selezionati e quelli no
    			processSelectedRowIndexes();
    		}
    		DataGridView::OnCurrentCellChanged(e);
    	}
    private:
    	/\*\*
    	\* lista di interi per tenere tracci dei valori selezionati
    	\*/
    	Collections::ArrayList ^s
    
    A 1 Reply Last reply
    0
    • A Andreoli Carlo

      Actually what i'm trying to do is to get a multiline rows selection without the problem of holding the ctrl key (i'm developing a touchscrenn app). By now i quite get it with a list of selected lines, but if i try to click fast on the rows it give me some painting error. Can someone give me a hint. (Maybe i should fire the ctrl command? i don't know how to simulate the pressdown command :( )

      #ifndef _CSTDGV_
      #define _CSTDGV_

      namespace primoAlpha {

      using namespace System;
      using namespace System::Drawing;
      using namespace System::Windows::Forms;
      using namespace System::Security::Permissions;
      
      /\*\*
       \* Classe per la gestione di un DataGridView personalizzato
       \* per una gestione tramite delegate del riordinamento delle colonne
       \* e per permettere di selezionare multiline senza il tasto control premuto
       \* 
       \* @author      Carlo Andreoli
       \* @version     0.1.0, 24/07/09 -- Prima versione (beta)
       \*/
      public ref class personalDataGridView : DataGridView
      {	
      public:
      
      	/\*\*
      	 \* Costruttore dove inizializzo le variabili che estendono la classe base
      	 \* 
      	 \* @author      Carlo Andreoli
      	 \* @version     0.1.0, 24/07/09 -- Prima versione (beta)
      	\*/
      	personalDataGridView()
      	{
      		this->selectedRowIndexes=gcnew Collections::ArrayList();
      		this->MultiSelectForced=false;
      	}
      	
      	/\*\*
      	\* variabile per gestire i selected senza il control selezionato
      	\*/
      	property bool MultiSelectForced
      	{
      		bool get() {
      			return \_MultiSelectForced;
      		} 
      		void set(bool value) {
      			this->\_MultiSelectForced = value;
      			this->selectedRowIndexes->Clear();
      			processSelectedRowIndexes();
      		}
      	}
      protected:
      	/\*\*
      	 \* override sulla funzione che gestisce CurrentCellChanged 
      	 \* per gestire il multiselect senza il tasto del ctr schiacciato
      	 \* @param		e
      	 \* 
      	 \* @author      Carlo Andreoli
      	 \* @version     0.1.0, 24/07/09 -- Prima versione (beta)
      	\*/
      	virtual void OnCurrentCellChanged (EventArgs^ e) override
      	{
      		if (this->CurrentRow!=nullptr && \_MultiSelectForced) {
      			int act\_row=this->CurrentRow->Index;
      		
      			if (selectedRowIndexes->Contains(act\_row)) {
      				selectedRowIndexes->Remove(act\_row);
      			}
      			else selectedRowIndexes->Add(act\_row);
      
      			//ora vado ad indicare i selezionati e quelli no
      			processSelectedRowIndexes();
      		}
      		DataGridView::OnCurrentCellChanged(e);
      	}
      private:
      	/\*\*
      	\* lista di interi per tenere tracci dei valori selezionati
      	\*/
      	Collections::ArrayList ^s
      
      A Offline
      A Offline
      Andreoli Carlo
      wrote on last edited by
      #2

      Ok i find myself :laugh: the solution...if you need...

      #ifndef _CSTDGV_
      #define _CSTDGV_

      namespace primoAlpha {

      using namespace System;
      using namespace System::Drawing;
      using namespace System::Windows::Forms;
      using namespace System::Security::Permissions;
      
      /\*\*
       \* Classe per la gestione di un DataGridView personalizzato
       \* per una gestione tramite delegate del riordinamento delle colonne
       \* e per permettere di selezionare multiline senza il tasto control premuto
       \* 
       \* @author      Carlo Andreoli
       \* @version     0.1.0, 24/07/09 -- Prima versione (beta)
       \*/
      public ref class personalDataGridView : DataGridView
      {	
      public:
      
      	/\*\*
      	 \* Costruttore dove inizializzo le variabili che estendono la classe base
      	 \* 
      	 \* @author      Carlo Andreoli
      	 \* @version     0.1.0, 24/07/09 -- Prima versione (beta)
      	\*/
      	personalDataGridView()
      	{
      		this->selectedRowIndexes=gcnew Collections::ArrayList();
      		this->MultiSelectForced=false;
      	}
      	
      	/\*\*
      	\* variabile per gestire i selected senza il control selezionato
      	\*/
      	property bool MultiSelectForced
      	{
      		bool get() {
      			return \_MultiSelectForced;
      		} 
      		void set(bool value) {
      			this->\_MultiSelectForced = value;
      			this->selectedRowIndexes->Clear();
      			processSelectedRowIndexes();
      		}
      	}
      protected:
      	/\*\*
      	 \* override sulla funzione che gestisce OnCellMouseDown 
      	 \* per gestire il multiselect senza il tasto del ctr schiacciato
      	 \* @param		e
      	 \* 
      	 \* @author      Carlo Andreoli
      	 \* @version     0.1.0, 24/07/09 -- Prima versione (beta)
      	\*/
      	virtual void OnCellMouseDown(DataGridViewCellMouseEventArgs^ e) override
      	{
      		DataGridView::OnCellMouseDown(e);
      		if (e!=nullptr && \_MultiSelectForced) {
      			int act\_row=e->RowIndex;
      		
      			if (selectedRowIndexes->Contains(act\_row)) {
      				selectedRowIndexes->Remove(act\_row);
      			}
      			else selectedRowIndexes->Add(act\_row);
      
      			//ora vado ad indicare i selezionati e quelli no
      			processSelectedRowIndexes();
      		}
      	}
      	/\*\*
      	 \* override sulla funzione che gestisce OnMouseMove 
      	 \* per gestire il multiselect senza il tasto del ctr schiacciato
      	 \* @param		e
      	 \* 
      	 \* @author      Carlo Andreoli
      	 \* @version     0.1.0, 24/07/09 -- Prima versione (beta)
      	\*/
      	virtual void OnMouseMove(MouseEventArgs^ e) override
      	{}
      private:
      	/\*\*
      	\* lista di interi per tenere tracci dei valori selezionati
      	\*/
      	Collections::ArrayList ^selectedRowIndexes;
      	/\*\*
      	\* variabile per gestir
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups