DataGridView: Scrolling to Selected row

(.NET 2.0 Framework)
In the DataGridView control, I have programmatically selected a row that's currently not displayed in the grid.  However, the grid does not seem to scroll to the selected row automatically, and there doesn't seem to be a way to scroll programmatically to any row, let alone the selected row.
Some details:
- my DataGridView is running under VirtualMode
- I first execute DataGridView.ClearSelection() then DataGridView.Rows[index].Selected = true
- I have traced the rows that aren't displayed and the pertinent properties are:
   DataGridViewRow.Visible = true
   DataGridViewRow.Displayed = false
I see no functions under DataGridView or DataGridViewRow to force the DataGridView to force a scroll.  Can anyone confirm this?  And is there a work around?

I wrote a small function that keeps the selected row in a datagridview centered. You can navigate my app with arrow keys, so this is essential. I call this after every key press. Note that if you only wanted the function to scroll when your selected row hit the bounds of your datagridview, remove the "halfWay" addition and subtraction from the if statement. Hope this helps someone. (Hurray for the first block of code I contribute)
Code Block
private void scrollGrid()
            int halfWay = (dataGridView.DisplayedRowCount(false)/2);
            if (dataGridView.FirstDisplayedScrollingRowIndex + halfWay > dataGridView.SelectedRows[0].Index ||
                (dataGridView.FirstDisplayedScrollingRowIndex + dataGridView.DisplayedRowCount(false)-halfWay) <= dataGridView.SelectedRows[0].Index)
                int targetRow = dataGridView.SelectedRows[0].Index;
                targetRow = Math.Max(targetRow-halfWay, 0);
                dataGridView.FirstDisplayedScrollingRowIndex = targetRow;

Similar Messages

  • How to maintain selected row in adf table displayed after refresh

    Hi,
    I am using jdev 11g
    I my jsf page I have a table with multiple rows.
    When i scroll and click on one of the rows its selected but if the page is refreshed the row is always selected but not displayed.
    I need to be able to maintain the selected row after the refresh of the page, so my table will look like its already scrolled to the selected row..
    I tried to use the attribute displayRow="selected" but it won't do the trick.
    Any hints
    Emile

    Hi Branislav,
    Kindly answer the following if you may.
    Is there a way to refresh the table after the selectListner is fired.
    Automatically when i select the table i need to refresh it.
    Why after refresh the selected row changes skin.
    Regards

  • Display of selected row no in table footer.

    Hi,
    Row no of first row is generally displayed in the footer of the table as
    Row <first row rowno> of <total no of rows>.Eg Row 1 of 10.
    Can this be changed to display row no of currently selected row insted of first row?
    Thanks in advance,
    Apurva.

    Hi ,
    You would not be able to extend the UI per se..
    Instead you can make use of the property "firstVisibleRow" and "visiblerows" .
    When a user clicks a button to bring down the entries by one
    - increase the firstvisiblerow property by 1
    when he wants to move to next page ,
    - increase the firstvisiblerow property to firstvisiblerow+visiblerows
    Use the table toolbar for scrolling..and placing your elements as it would always be properly aligned to your table..
    Regards
    Bharathwaj..

  • How to read 'clicked header' AND selected row from multicolumn listbox?

    I have a multicolumn listbox filled with 6 columns and about 500 rows.
    I want the user to be able to click on a column header, and sort the listbox alphabetically on that column. I've written the code for that, and that works. (using the 'itemnames' en 'get clicked col hdr' properties.)
    However, I also want to include the option, that when a user highlights a row, and then clicks on the header, that after the listbox gets sorted it scrolls down to the selected row.
    (So that the user doesn't have to search for it)
    And that's where things go wrong, because the value of the listbox changes to zero when you click on a column header. No I idea why it does that, but it's rather
    annoying. Can I change that behaviour somehow?
    Or any ideas how to get around it?

    My thanks to you and Jared.
    Seems I got a working solution now.
    Did take a while to figure out why your solution worked. Basicly, you're reading the row from a few iterations before.
    As soon as I understood that, I simplified it a little. Look at the attached file... I think it does the same. :-)
    Jared asked for the sorting routine. As I don't seem to be able to attach files when replying to comments, I took the liberty to include it here also.
    Basicly, I just use the 'sort 1D array' that comes with Labview 6. To be able to sort a 2D array, I convert every row to a cluster. That's something the 'sort 1D array' VI can handle nicely.
    To sort on the correct column, I just cut all columns in front, and paste them behind again. A
    fter sorting, I reverse the process.
    Anthony.
    Attachments:
    copy2_of_multicolumn.vi ‏26 KB
    sort_2d_string_array.vi ‏34 KB

  • Select Table row(eg.3rd),rows displayed from the selected row,hiding above

    If we move the horizontal scroll bar of the table and filter a column when there is a selection on the row, the rows are displayed from the selected row. The rows above the selected rows are disappearing(F5 it come back) and the rows are available when there are more rows with vertical scroll bar(above the selected row, if we scroll up).

    Frank,
    Mailed to you the sample application with the table script too. Please review the comments in the mail.
    Thanks and Regards,
    Stanley William
    Edited by: STANLEYWILLIAM on Apr 22, 2013 3:52 PM
    Edited by: STANLEYWILLIAM on Apr 22, 2013 3:52 PM

  • 3.2; BC4J, GridControl; Select row programatically?

    Hi,
    I need to programatically Highlighted a desired row (which i know the primary key) from a grid and scroll the grid to show this selected row in the view port area.
    Any property/way for this ?
    note that: define a WHERE clause for rowSetInfo and .executeQuery() cause to show only the qualified rows. and this is not my purpose.
    Please Advice.
    Ali

    Sathish,KKirk
    With your suggestion i wrote following code.
    It found the desired row and highlighted, but grid doesn't scroll to show this row on the view port.
    So, now how can i scroll the grid to show the row?
    try{
    ScrollableRowsetAccess systemRs = (ScrollableRowsetAccess)SystemViewRowSetInfo.getRowsetAccess();
    systemRs.absolute(1);
    do{
    ImmediateAccess iSys= (ImmediateAccess)systemRs.getColumnItem("SystemCode");
    String sSys = iSys.getValueAsString();
    if (sSys.equals(100)) {
    break;
    }while (systemRs.next());
    }catch(Exception ex){
    ex.printStackTrace();
    null

  • Dynpro table - footer and highlight selected row

    I have two questions reg. tables: WebAS 6.40 SP13
    a) Although I set the property footerVisible to false, I do still have this navigation footer visible. Is there another condition which must be met in order to hide it (e.g. design alternating works only in readOnly mode)?
    b) Is there a way to have selectionMode Single without this box in the first column (only highlighting the selected row with this orange frame).
    Thanks F.

    Thanks folks for your support. Maybe I should have described what I am going to do: I want to realize a table where the first two columns are fixed, while the rest of the columns are scrollable (horizontally).
    I have used two tables, both referring to the same model (singleton). The second table (to the right) is in a scrollable container, so I can scroll horizontally. For the user this looks like one table, only the second part is scrollable. All works fine, except for the two things I have posted:
    a1) Since I already have a footer for navigation in the first table, I want to hide the one in the second table.
    a2) In the NWStudio the footer is hidden when I set footerVisible false, but in the Browser it is still there.
    b1) Since I have already the lead selection boxes in the first table, I do not need it in the second.
    b2) However, I still want to indicate the selected row (spanning two tables). Since the same(!) model data are used, this works when I have selection mode single. I do not even have to program anything, any selection in the first table highlights the same row in the second - only I do not want to have the boxes twice.

  • RichTable moves Selected Row to the Top of my tableview on refresh

    When I issue a partialtrigger on a table with a selected Row, the selected row is repositioned to be the first Row that is available. The actual positions of the rows in the tables dont change, the selected row is just scrolled to the top... I need to suppress this behavior. Anyone have any Ideas?

    Without an exact jdve version we can't do much.
    Check these properties of hte table
    activeRowKey, displayRowKey and displayRow. Then read the doc for the properties and set them according your use case.
    Timo

  • Shift-scroll not selecting multiple messages

    I've got two questions, but I'll post them separately to keep the threads clean...
    I just got a Curve 8330 (used to have an 8830 World Edition, with Sprint in case it matters) and I'm loving it so far. But for some reason, I can't click the SHIFT key and scroll to select multiple messages like I could on the other BB. I've tried about every combination I could think of: Left shift, right shift, alt, press and don't hold, press and hold, press both and hold, alt-shift and scroll. Nothing.
    Is it a software problem?
    Is there some weird "don't allow shift to be used for multiple selection" setting some place.
    Oh... and yes, the Shift key works just fine for other uses.
    Ideas?

    Hi and welcome to the forums,
    I have an Verizon 8330. You should be able to use either the right or left keys to press and scroll.
    Not to be insulting, but to verify,  the keys are located on the bottom row last key on each side of the keyboard.
    They have an up arrow in silver along with an aA in each. You should be able to highlight the message to start, press either shift key, and scroll the trackball to the last selected item. 
    I was just verifying the procedure.
    Has this not worked since you got it, or has it just started?
    Please let me know,
    Thanks
    Message Edited by Bifocals on 08-30-2008 04:15 AM
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

  • Selected row in JTable should

    Hi
    In my JTable i'am hilighting the selected row with blue color and the Selected row will be changing dynamically during run time, this is working fine but the problem is:-
    when selected row crosses the visible space it's Hilighted but unless i manually scroll down it's not visible, so i
    Can any one tell me how to set the scrollbar to adjust so that selected row is always visible with in vissible space and i neednot scroll down to see
    Thank's in Advance for any advice/suggestions

    Well this method is taking Rectangle as the parameter so i tried the following :-
    table.scrollRectToVisible(new Rectangle(table.getSelectedRow(),table.getSelectedColumn(),1,1));
    Am not sure about it but still i'll give a try
    Anyways Thank's a lot for the Replay, Atleast i got a hint to give a try
    THANK AGAIN

  • After upgrading to CF10, the selected row of my cfgrid is no longer passed on form post.

    I have a cfform which contains a cfgrid and prior to the 9 to 10 update, upon submission of the cfform, the selected row of the grid was passed/posted to my form action page as:
    __CFGRID__gridForm__renewalGrid
    This contained all the data from the selected row, I.e.:
    __CFGRID__COLUMN__=PROJECTID; __CFGRID__DATA__=T01081002AP; __CFGRID__COLUMN__=APPLICATIONS; __CFGRID__DATA__=PQFD; __CFGRID__COLUMN__=OWNERUID; __CFGRID__DATA__=HT2008; __CFGRID__COLUMN__=TEAM; __CFGRID__DATA__=Roberts; __CFGRID__COLUMN__=ROLE; __CFGRID__DATA__=AASBOAPMX; __CFGRID__COLUMN__=REGION; __CFGRID__DATA__=Southwest; __CFGRID__COLUMN__=EXISTING; __CFGRID__DATA__=K8045F; __CFGRID__COLUMN__=SOD; __CFGRID__DATA__=0; __CFGRID__COLUMN__=INITIALEMAILDATE; __CFGRID__DATA__=01/28/2013; __CFGRID__COLUMN__=MESSAGEDATE; __CFGRID__DATA__=; __CFGRID__COLUMN__=SECONDEMAILDATE; __CFGRID__DATA__=; __CFGRID__COLUMN__=ESCALATIONDATE; __CFGRID__DATA__=; __CFGRID__COLUMN__=COMPLETEDBY; __CFGRID__DATA__=TH2878; __CFGRID__COLUMN__=COMPLETIONDATE; __CFGRID__DATA__=02/06/2013; __CFGRID__COLUMN__=MONTHPULLED; __CFGRID__DATA__=Jan2013; __CFGRID__COLUMN__=TOTALITEMS; __CFGRID__DATA__=2; __CFGRID__COLUMN__=RELIEVINGPSA; __CFGRID__DATA__=; __CFGRID__COLUMN__=MODIFIEDBYTS; __CFGRID__DATA__=02/06/2013; __CFGRID__COLUMN__=MODIFIEDBY; __CFGRID__DATA__=T228Y8; __CFGRID__COLUMN__=CREATEDBY; __CFGRID__DATA__=KV3M36; __CFGRID__COLUMN__=CREATEDTS; __CFGRID__DATA__=01/28/2013; __CFGRID__COLUMN__=NEWSA; __CFGRID__DATA__=; __CFGRID__COLUMN__=DELEGATESTATUSNOTE; __CFGRID__DATA__=Access; __CFGRID__COLUMN__=STATUS; __CFGRID__DATA__=Completed; __CFGRID__COLUMN__=DATATYPE; __CFGRID__DATA__=Appl New
    After upgrading to CF10, and with no changes to the code, performing this same process, __CFGRID__gridForm__renewalGrid is still passed in the form scope to my action page, but now it is empty.
    I have not yet uninstalled CF9, so I brought it up on a different port, and I can run the same code as CF9 or CF10 and watch... in 9 the selected row is passed, in 10 it is empty.
    Is this a bug? Is there a work around? Please help.

    appears that apple has changed SMB code, and now its not possible login from windows on mac.
    i installed snow leopard and now works fine.
    apple is capable to make it run paying new license of smb code, but isnted of this, apple has created new protocol smbx and now, all others need to adapt your code to apple..
    bad movement.. i am thinking sell imac and no back to apple anymore..

  • How do I set only the first row of a DataGrid as the selected row?

    I have a "Go" button on a search form that fetches data into an already data bound grid.  After the data is fetched, I want to make the first row in the Datagrid the selected row, as if the user clicked on it.  If the result set is empty, I don't want the code to crash.  (I only want one row to be able to be selected at a time)
                protected function btnGo_clickHandler(event:MouseEvent):void
                    getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);
                    grdSBJs. //  ?????  What goes here to select the first row?

    This should do it.
    If this post answered your question or helped, please mark it as such.
    if(myDataGrid.dataProvider.length > 0){
      myDataGrid.selectedIndex = 0;

  • Select row button not getting displayed in alv grid.

    Hi ,
    As per my requirement I am using tab strip in module pool.
    Each tab strip is containing one ALV.
    And user can change delete or create one record when the alv is displayed.
    The same should be saved in the database and ALV should be refreshed.
    When I am displaying the ALV the left most option of the ALV with which I can select the whole row is not coming.
    Because of which I am unable to call the method to get the selected row and delete or change accordingly.
    Why this button is not coming?
    I am using set_table_for_first_display in my program.
    Please help.

    Hi,
    In the method SET_TABLE_FOR_FIRST_DISPLAY, you will have to change the Selection Mode to 'A'. I guess you are not passing any values to the Layout parameters.
    Once you do that, you will find what your are looking for.
    Data : LA_LAYO type LVC_S_LAYO.
    LS_LAYO_SEL_MODE = 'A'.
    and pass this to the method's layout parameter.
    Cheers,
    SKC,

  • Get values from selected row in a Table?

    Hello.
    I'm on VC 7.1 (the trial version downloaded from SDN).
    I'm trying to figure out a way to retrieve some values from the currently selected row in a Table element through the output connector.
    I have a web-service which returns results to the Table, and I want the user to be able to select one of the rows and then trigger another web-service call with some of the values from that row -- is this possible?
    Also, I can't find any documentation that lists what can and can't be done with each UI element, is there something like this some where? (the Modeler's guide doesn't help, and the Reference guide seems to focus on menu items and what the VC screen looks like)
    Thanks,
    Alon

    Hi Alon
    This is a very simple task.
    You just need drag the service which you want to execute, after select row, in model.
    Drag output connector from table to input connector of service. Then map the parameter.
    Regards
    Marcos

  • Get selected row values from Table view control

    Hi ,
    I am using transaction ME23N, would like to access row values from item table for selected row. I have written a script as in screen shot and its giving me error at java script step two. I want to get the PR number from item table for selected row.
    With Regards
    Vishal Lokapur

    H Vishal,
    Can you please share how you were able to resolve the issue regarding the selected row
    in case of a table control .
    Regards

Maybe you are looking for

  • Time for a new card...help me choose!!! MSI, ECS, EVGA????

    I'm planning to get a new card TODAY! I'm down to a couple of cards and must make a decision and place an order before midnight    (rebates expire April 30th on some of these). Since this is an MSI forum feedback on this card would be great... MSI NX

  • Place assets only on First page

    Hi Forum, I m wondering, if can i place my Library assets.item(0) only on first page. Because the below script places the Library assets, when i click a particular page... Instead, when i run the script, the assets should be placed only on the first

  • Pdf form fields

    I have a report that i output as pdf. is it possible to include a form field in a pdf output such that i can download the Report and type some comments in the form field and save the document?

  • Event handlers inheritence

    Do You plan to add some inheritence into event handlers. Example: I have event defined in UIX page and i have same event registred at global level through PageBroker. Do You know how can I handle event with same name before globally defined?

  • Problem with AVCHD

    I am having MAJOR problems in AE CS4 getting my 1920 x1080 .mts files (AVCHD from Sony HVC-F11) to export without serious unusable  flickering/stuttering although the exact same file exports fine in Premiere CS4 when burning in Encore CS4.  I'm not s