msFlexGrid, Highlight Only one line
Posted on 2007-08-11
I am trying to use msFlexGrid in my VB6.0 project. I have been succesful in defining and loading the grid on the form. I would like my users to select one row on the grid. based on the contents of the row they select, I will know what action to take.
Each line on the grid is mutually exclusive. It only makes sense for the user to select one line at a time.
My testing was going great. I would click (single click, left mouse button, release left mouse button) on a row and the correct action would be taken. Then I tested by pressing and holding the left mouse button while I dragged through the msFlexGrid. I then released the left mouse button. The result: All the lines that I dragged through were highlighted. The good news was that it only executed the 'click' event for the row I released the mouse button on, not every row that was highlighted. The bad news is that I think/know that seeing all of the highlighted lines would be very confusing to the user. They shouldn't be able to select/highlight more than one line.
I looked for but didn't find a property similar to the multi-select/single select for listboxes that would control this behavior. I searched EE and found a post that I thought was asking the same question. The accepted answer on that post was to put the following code in the click event of the flexGrid.
.RowSel = .Row
.ColSel = .col
This was an impovement. sort of. The result of that code was the no line was ever highlighted, even if I clicked on a just a single line. I would like the 'clicked' line to be highlighted, just not all of the 'dragged over' lines. Is there some way to ensure that only one row can be selected/highlighted at a time? Even if the user drags the mouse while holding the left button down, I would prefer that only one row be higlighted at a time. If that can't be accomplished, would it be possible to make sure that only the row they ended up on when the mouse button was released is highlighted when the drag is complete? At least then the user would only see one highlighted line and they would know which action was initialted.