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. DataGridView ClearSelection() behavior

DataGridView ClearSelection() behavior

Scheduled Pinned Locked Moved C#
helpquestion
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
    Matthew Cuba
    wrote on last edited by
    #1

    Hello, I have noticed a particular behavior in a program I am developing. I am interested if anyone might have a solution in mind. I've got a TabControl with 6 TabPages on it. Each TabPage has a DataGridView on it and when the user selects a row on one of these DataGridViews, my program responds in some way that isn't germane to the problem. The desired behavior is that the user is always presented, when selecting a TabPage, with a DataGridView with all rows unselected. Here is a code snippet to illustrate what I currently do to accomplish this: private void tabControlPageSelected(object sender, TabControlEventArgs e) { (e.TabPage.Controls[0] as DataGridView).ClearSelection(); } The behavior that I see is that, despite explicitly calling DataGridView.ClearSelection() after the population of these DataGridViews and again in response to the Selected event using the code above, as I click through the tab pages, the first row of each is initially highlighted. Once I have navigated to a new tab page and navigate back to the previous one, the highlighting is gone, as desired. Code to test if any rows are selected tells me that none are, and it appears that the highlighting is simply a cosmetic annoyance, but that annoyance is confusing to the user and my primary goal is to make the program intuitive and free from annoyances. Any ideas? Thanks much, Matt It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point?

    D 1 Reply Last reply
    0
    • M Matthew Cuba

      Hello, I have noticed a particular behavior in a program I am developing. I am interested if anyone might have a solution in mind. I've got a TabControl with 6 TabPages on it. Each TabPage has a DataGridView on it and when the user selects a row on one of these DataGridViews, my program responds in some way that isn't germane to the problem. The desired behavior is that the user is always presented, when selecting a TabPage, with a DataGridView with all rows unselected. Here is a code snippet to illustrate what I currently do to accomplish this: private void tabControlPageSelected(object sender, TabControlEventArgs e) { (e.TabPage.Controls[0] as DataGridView).ClearSelection(); } The behavior that I see is that, despite explicitly calling DataGridView.ClearSelection() after the population of these DataGridViews and again in response to the Selected event using the code above, as I click through the tab pages, the first row of each is initially highlighted. Once I have navigated to a new tab page and navigate back to the previous one, the highlighting is gone, as desired. Code to test if any rows are selected tells me that none are, and it appears that the highlighting is simply a cosmetic annoyance, but that annoyance is confusing to the user and my primary goal is to make the program intuitive and free from annoyances. Any ideas? Thanks much, Matt It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point?

      D Offline
      D Offline
      dsl fahk
      wrote on last edited by
      #2

      both of these ways are basically cheating :)(they still work), but maybe in the onLoad you could do a foreach statement that deselects everything, and if that doesn't work, you could try making a foreach that selects every tab page once before the form is actually shown. Sorry for a lack of a better answer. X|

      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