To assign one column to a datagridselectedcolumn

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Smish
    New Member
    • Jan 2007
    • 51

    To assign one column to a datagridselectedcolumn

    Hi,

    Please can any one help me out.ITs urgent.

    I have a DataGridViewSel ectedCellCollec tion object,i would like to assign an enitre column of my datagridview to this DataGridViewSel ectedCellCollec tion object .I cant set selection mode to coulmn header cos already row header is being used.

    Please guide me..Thanx.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    If your selection mode is such that a whole row is selected, I am pretty sure you cannot select something other a whole row.

    You could maybe "fudge" it a little. Set your SelectionMode to CellSelect.
    Then in the various click events (cell mouse click ?), if its NOT on a column header, set the selected cells to be all the cells in a row. You will probably also have to handle something if they use the arrow keys to change the selection
    That should effectively create the 'full row select' effect.
    If it *IS* a column header, set all the cells in that column as selectedcells.

    You would have to play with it a bit, but it should work

    Comment

    • Smish
      New Member
      • Jan 2007
      • 51

      #3
      hi,

      I want to kno is ther any way to set the cells in the entire column as selected cells.
      like..If i do a for loop whioch will assign the cell values.

      I tried

      DataGridViewSel ectedCellCollec tion obj = null;

      for(int r =0;r<datagridvi ew.rowcoun;r++)
      {
      obj[index].value = datagridview[column,row].value;
      }

      here am getting an error object set to null refernce..

      if some how i get to assign the selected cells to my DataGridViewSel ectedCellCollec tion then the problem is solved..

      Please do reply thanx...

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        You are getting a null reference because you are setting the object to null!
        Right here:
        DataGridViewSel ectedCellCollec tion obj = null;

        Comment

        • vanc
          Recognized Expert New Member
          • Mar 2007
          • 211

          #5
          Originally posted by Smish
          hi,

          I want to kno is ther any way to set the cells in the entire column as selected cells.
          like..If i do a for loop whioch will assign the cell values.

          I tried

          DataGridViewSel ectedCellCollec tion obj = null;

          for(int r =0;r<datagridvi ew.rowcoun;r++)
          {
          obj[index].value = datagridview[column,row].value;
          }

          here am getting an error object set to null refernce..

          if some how i get to assign the selected cells to my DataGridViewSel ectedCellCollec tion then the problem is solved..

          Please do reply thanx...
          You get error because there are rows that you haven't set value to. If you set value to all cells in your DGV then you will not get that error again. You're on the right track with your code, but if you want to click a cell within the Grid to select all row that cell belong to you can combine with cell click event and you will get position of that cell in event argument --> easier.

          Comment

          • Smish
            New Member
            • Jan 2007
            • 51

            #6
            ther are other functions in event click ...so i tght on a particluar click if i get the column vlaue then i cn asign cells to selected value so tht entire selected object can be passed......... jss guide me

            Comment

            • MrMancunian
              Recognized Expert Contributor
              • Jul 2008
              • 569

              #7
              Originally posted by Smish
              ther are other functions in event click ...so i tght on a particluar click if i get the column vlaue then i cn asign cells to selected value so tht entire selected object can be passed......... jss guide me
              How about re-reading your post to check for typo's? This just doesn't make sense...

              Steven

              Comment

              • Smish
                New Member
                • Jan 2007
                • 51

                #8
                i assign a menu to entire column in the datagridview,th en when i click select entire column frm the menuiten then what i want is the entire column should be selected in to an object which is of type DataGridViewSel ectedCellCollec tion.

                I want this because i already have made a function which takes selected cell values so tht i dnt need to modify the functions.

                Comment

                • Smish
                  New Member
                  • Jan 2007
                  • 51

                  #9
                  Hi please...could ne1 solve my this problem......


                  i want to assign an enitre column to the DataGridViewSel ectedCellCollec tion object...its very urgent.....

                  Comment

                  Working...