C# DataGrid manipulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chathura86
    New Member
    • May 2007
    • 227

    C# DataGrid manipulation

    i'm building a windows application with c# .net

    i have a search window where i make a sql and set the result in to a datagrid

    i want to add a button column to this datagrid so when the button is pressed

    a label in the same form will display the value of the cell in the first column of selected row

    eg.

    | Col1 | Col2 | Col3 | BtnCol |
    | 10 | asdas | sdasd | button1 |
    | 20 | asdas | sdasd | button2 |
    | 30 | asdas | sdasd | button3 |
    | 40 | asdas | sdasd | button4 |
    | 50 | asdas | sdasd | button5 |


    if i clicked the button3 the label should display the value 30

    can this be done?
    if so how?

    Thank you

    chathura bamunusinghe
  • Jimmy611
    New Member
    • Jan 2007
    • 49

    #2
    Yes it can be done. When you click on the button, just get the value of that particular cell by current active row and set the label.text to the text of that cell.
    Last edited by Jimmy611; Jun 18 '08, 06:22 AM. Reason: edit message

    Comment

    • chathura86
      New Member
      • May 2007
      • 227

      #3
      Well the problem is adding a button column to the datagrid


      Originally posted by Jimmy611
      Yes it can be done. When you click on the button, just get the value of that particular cell by current active row and set the label.text to the text of that cell.

      Comment

      • balame2004
        New Member
        • Mar 2008
        • 142

        #4
        Originally posted by chathura86
        Well the problem is adding a button column to the datagrid
        Add a column (Type - DataGridButtonC olumn) in datagrid and also add common event method to the buttons. You can add the column through Column collection property of DataGrid control

        Comment

        • balame2004
          New Member
          • Mar 2008
          • 142

          #5
          Use Cell Click or CellContent click event of datagrid to write source code to take some action when button is clicked

          Comment

          Working...