none
Datagridview and down arrow to move down rows

    Dotaz

  • With a two column Datagridview, first column with a number in it, and second column with nonwrap text.  When the datagridview width is less than the width of the data in the two columns, the only way I can get a horizontal scrollbar to show is with the width set for both columns. If I then try to scroll down the rows using the down arrow, the grid jumps to show only the second column. I have tried various settings for the columns - fill - fillweight - autosize etc.

    I found one solution, setting the first column to frozen in the key down event and then setting it back in the key up event but the scrollbar does flicker and I am sure this is not the correct way to do this.

    The user needs to scroll down the rows and be able see the first column whilst doing this and then if necessary scroll right to read any text not visible. 

    Any help would be appreciated, Thanks.

    David

    13. března 2012 18:33

Všechny reakce

  • Hi David,

    Sorry but can I pester you for just a bit more detail?  You've done pretty well in describing the entire issue, but I'm affraid you've used a few descriptive terms that I'm hesitant to assume the meaning of, and there are a few more details I'd like to have...

    1. Is either column read only?  Or can both be edited? 
    2. Just to verify, the DataGridView's ScrollBars property is set to either Both or Vertical, correct?
    3. Is the gridview bound to a BindingSource component? Some other data source? Or unbound (virtual)?
    4. What do you mean by "the grid jumps to show only the second column"? Obviously the grid doesn't "hop" from one spot to another =P, but do you mean to say that it automatically scrolls to the right? If so, is it all the way to the max of the scroll bar or just until the left edge of the right-most column is in line with the left edge of the gridview control?
    5. In addition to the column fill mode, what is the value of the gridview's AutoSizeColumnsMode property? Does the grid allow the user to resize columns?

    Ok thats good for now cause the answer could be in that list of questions - especially if column1 is readonly.  Arrow key navigation kind of assumes an edit control in the column by default, so you might wind up having to handle the key press event on the gridview to manually change the selected cell and supress telling the grid about the key (unless you detect that the user is editing inside a cell and needs the up/down arrow key to edit multiline text, then you would skip your code and pass the keystroke onto the control).
    -EDIT-

    Acutally, you wouldnt so much manually set the selected cell as you would calculate the required scroll position based on the next row index and then scroll to that position with the scroll.x set to 0.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    13. března 2012 19:24
    Moderátor
  • Hi David,

    Sorry but can I pester you for just a bit more detail?  You've done pretty well in describing the entire issue, but I'm affraid you've used a few descriptive terms that I'm hesitant to assume the meaning of, and there are a few more details I'd like to have...

    1. Is either column read only?  Or can both be edited? 
    2. Just to verify, the DataGridView's ScrollBars property is set to either Both or Vertical, correct?
    3. Is the gridview bound to a BindingSource component? Some other data source? Or unbound (virtual)?
    4. What do you mean by "the grid jumps to show only the second column"? Obviously the grid doesn't "hop" from one spot to another =P, but do you mean to say that it automatically scrolls to the right? If so, is it all the way to the max of the scroll bar or just until the left edge of the right-most column is in line with the left edge of the gridview control?
    5. In addition to the column fill mode, what is the value of the gridview's AutoSizeColumnsMode property? Does the grid allow the user to resize columns?

    Ok thats good for now cause the answer could be in that list of questions - especially if column1 is readonly.  Arrow key navigation kind of assumes an edit control in the column by default, so you might wind up having to handle the key press event on the gridview to manually change the selected cell and supress telling the grid about the key (unless you detect that the user is editing inside a cell and needs the up/down arrow key to edit multiline text, then you would skip your code and pass the keystroke onto the control).
    -EDIT-

    Acutally, you wouldnt so much manually set the selected cell as you would calculate the required scroll position based on the next row index and then scroll to that position with the scroll.x set to 0.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Hi Reed,

    Thanks for replying and taking the time to go through this.

    1. Both columns are read only, readonly is set to false as are all the allowuser........

    2. ScrollBars property is both.

    3. This a Unbound datagridview.

    4. It automatically scrolls to the right so as just hide first (lefthand) column, the second column still has text not shown to the right, so you can move the scroll bar further to the right.  Yes as you said "just until the left edge of the right-most column is in line with the left edge of the gridview control? "

    5. AutoSizeColumnsMode property is set to "none"

    The data added by code, reading from files are Songs, first column has verse number and second column the lines of each verse with a blank line in between verses. When user clicks any line within a verse that verse is displayed on projector screen.  Where there are more lines than can be displayed at a given size the words can be scrolled and this where the down arrow comes in, but as stated the column with verse number disappears.  So the thing the user can do is select a row.

    Hope this answers the questions, and thanks for your help.

    David

    13. března 2012 21:29