dataGridView Selection?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Djiber
    New Member
    • Apr 2012
    • 15

    dataGridView Selection?

    Is it possible and how to disable selection of 1'st row in dataGridView.

    I made it select some other row, but even so when u try to move with arrows on keyboard it'll select 2'nd row(cause 1'st row was selected initially and you can see it's selected on RowHeader-1'st/Left Column)

    This is my code for selecting row:

    Code:
    dataGridView1.ClearSelection();
    dataGridView1.Rows[BoPrI].Selected = true;
    dataGridView1.FirstDisplayedScrollingRowIndex = BoPrI;
    BoPrI is int variable that has Index Value
  • RhysW
    New Member
    • Mar 2012
    • 70

    #2
    write a bit of code that is fired everytime the selected row is changed, make this code check if row 0 is selected, if it is, set selected row to row 1.

    Comment

    • Djiber
      New Member
      • Apr 2012
      • 15

      #3
      Hmmm, now I'm not sure if you didn't understand me or I don't understand you :P

      This ^^ is code that fires everytime selected row is changed cause it's a part of refresh function and now like I've said it does work it selects the row I wish it to select, it focus it so if it's in the middle of the database it'll go to it and select it so it scrolls to it and everything.

      On Form I have edit button that when you click it will edit that selected row, with pressing enter you will edit selected row and now we came to but...

      When you click Down Arrow on Keyboard it acts like 1'st row was selected and it selects 2'nd row. (If you have visible Row Header you can see that after refresh there's an arrow tag on 1'st row even so some other row is/was selected and by selected I mean it's whole blue and any action that I send to selected row will apply to it and not to 1'st row)

      Comment

      • RhysW
        New Member
        • Mar 2012
        • 70

        #4
        so whats the problem? you said you dont want it to select the frist row, then explained that it started with the second row anyway, im not seeing what the problem is :S

        Comment

        • Djiber
          New Member
          • Apr 2012
          • 15

          #5



          Red/Selected Row is row that I've selected, edited, then refreshed grid and reselect it (When I click on "Promjeni" button/Edit button I can edit that row and it'll reselect it again)

          Blue/Phantom Selected Row is row that gets autoselected (You can notice the arrow/triangle on the Row Header) If I click Down arrow DataGridView will act like 1'st row was selected and it'll select 2'nd row/If I click Up arrow nothing will happen cause 1'st row is selected.

          How to stop autoselection of Blue row or make it autoselect my reselected Red row(I want that Arrow/Triangle from Blue row to be on my Red row) :P

          Hope picture helped to understand my problem, if not I'm gonna make Power Point Presentation or Movie :P
          Last edited by Djiber; May 4 '12, 01:18 PM. Reason: Can't see picture

          Comment

          • RhysW
            New Member
            • Mar 2012
            • 70

            #6
            oh i see, you mean how to make it show the little black arrow pointing to the actual line thats selected?

            wow what version of visual studio are you using btw?

            these quotes from the link at the bottom of this answer, though the logic should help you now that i know what youre on about XD i honestly couldnt figure out what you mean but the picture helped :L they speak a thousand words you know, but i would love to see you make this into a movie just for me ;)

            Code:
            The row gets selected, (the cells in the row are highlighted), but the little black arrow in the column to the left of the data stays at the previously selected row.
            Code:
            I've worked it out.
            I need to make the row the current row.
            CurrentRow is readonly, but setting the current cell has the desired effect.
            The home for technical questions and answers at Microsoft. Get started asking, answering, and browsing questions about products like .Net, Azure, or Teams.

            Comment

            • Djiber
              New Member
              • Apr 2012
              • 15

              #7
              I'm using Visual C# 2010 Express

              SRY I didn't reply sooner, but didn't have access to internet over the weekend.

              Yes I've thought picture may help, cause it's hard to explain it on my language and even harder on English, I don't speak it that often :P

              I'm gonna check that thread, try to implement it and check does it solve my problem.

              Thanks for the reference

              Edit:
              Yap setting current cell property worked like a charm:

              Code:
              dataGridView1.CurrentCell = dataGridView1.Rows[BoPrI].Cells[0];
              Thanks again for the help
              Last edited by Djiber; May 7 '12, 07:24 AM. Reason: Solved problem

              Comment

              Working...