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. C#
  4. Excel like Selection?

Excel like Selection?

Scheduled Pinned Locked Moved C#
question
2 Posts 2 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.
  • M Offline
    M Offline
    Megidolaon
    wrote on last edited by
    #1

    I might have asked this before, but I never got any good answer. How do I implement an excel like selection? I have a collection of many controls arranged in lines and rows, much like excel cells. The user i supposed to select them like cells in Excel, but it just won't work. The controls' MouseDown and MouseEnter event apparently cause the control to own the mouse and make it impossible to fire events on any other control as long as the mouse button is held down. I also got this code on msdn, but it's utter rubbish. It will cause a single control to flicker between selected and unselected madly, it's not possible to select multiple controls and the control isn't drawn while you hold the mouse over it.

    Point start;
    private void pictureBox_MouseDown(object sender, MouseEventArgs e)
    {
    start = e.Location;
    }

    	private void pictureBox\_MouseMove(object sender, MouseEventArgs e)
    	{
    		if (e.Button == MouseButtons.Left)
    		{
    			Size selSize=new Size(e.X - start.X, e.Y - start.Y);
    			Rectangle selRect = new Rectangle(start, selSize);
    			selRect.Offset(((Control)sender).Location);
    			foreach (Control ctl in this.flowLayoutPanel1.Controls)
    			{
    				if (ctl.Bounds.IntersectsWith(selRect))
    				{
    					// Here goes your code for doing whatever you need to "select"
    					// the picture box...
    
    					ctl.BackColor = Color.Yellow;
    				}
    				else
    				{
    					// Here goes your code for doing whatever you need to "deselect"
    					// the picture box...
    
    					ctl.BackColor = Color.Gray;
    				}
    			}
    		}
    	}
    

    So, does anyone have a solution or at least a hint? Tanks a lot!

    C 1 Reply Last reply
    0
    • M Megidolaon

      I might have asked this before, but I never got any good answer. How do I implement an excel like selection? I have a collection of many controls arranged in lines and rows, much like excel cells. The user i supposed to select them like cells in Excel, but it just won't work. The controls' MouseDown and MouseEnter event apparently cause the control to own the mouse and make it impossible to fire events on any other control as long as the mouse button is held down. I also got this code on msdn, but it's utter rubbish. It will cause a single control to flicker between selected and unselected madly, it's not possible to select multiple controls and the control isn't drawn while you hold the mouse over it.

      Point start;
      private void pictureBox_MouseDown(object sender, MouseEventArgs e)
      {
      start = e.Location;
      }

      	private void pictureBox\_MouseMove(object sender, MouseEventArgs e)
      	{
      		if (e.Button == MouseButtons.Left)
      		{
      			Size selSize=new Size(e.X - start.X, e.Y - start.Y);
      			Rectangle selRect = new Rectangle(start, selSize);
      			selRect.Offset(((Control)sender).Location);
      			foreach (Control ctl in this.flowLayoutPanel1.Controls)
      			{
      				if (ctl.Bounds.IntersectsWith(selRect))
      				{
      					// Here goes your code for doing whatever you need to "select"
      					// the picture box...
      
      					ctl.BackColor = Color.Yellow;
      				}
      				else
      				{
      					// Here goes your code for doing whatever you need to "deselect"
      					// the picture box...
      
      					ctl.BackColor = Color.Gray;
      				}
      			}
      		}
      	}
      

      So, does anyone have a solution or at least a hint? Tanks a lot!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Why is your mouse move firing for movement only in a picture box ? This code looks pretty logical to me.

      Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

      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