How to get command column name

7 posts, 0 answers
  1. ewart
    ewart avatar
    221 posts
    Member since:
    Jan 2007

    Posted 17 Nov 2008 Link to this post



         
    private void myGrid_CommandCellClick(object sender, EventArgs e) 
          { 
             GridCommandCellElement gCommand = (sender as GridCommandCellElement); 
     
             if( gCommand.ColumnIndex == 11 ) 
                 // code..
          } 
     

    Simple question - I have two command buttons and wondered if it's possible to get the unique name from within the event?! can only find the column index number.    gCommand.Name returns ""

    Cheers
      Ewart.

  2. Nick
    Admin
    Nick avatar
    767 posts

    Posted 19 Nov 2008 Link to this post

    Hi ewart,

    Thank you for your question. Here is the code you need to use:

    MessageBox.Show(gCommand.Value.ToString()); 
     

    Do not hesitate to write me back if you have further questions.

    All the best,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. ewart
    ewart avatar
    221 posts
    Member since:
    Jan 2007

    Posted 21 Nov 2008 Link to this post

    Sorry, thats the value; I wondered if it's possible to get the unique name from within the event? 

    cheers
    ewart
  4. Nick
    Admin
    Nick avatar
    767 posts

    Posted 21 Nov 2008 Link to this post

    Hi ewart,

    Thank you for your questions.

    If you need just row number you can use gCommand.RowIndex.

    You may use another cell on the same row to distinguish between click on one row or another:

    this.radGridView1.Rows[gCommand.RowIndex].Cells[5].Value 
     
    The code above accesses the cell value in the 6th cell on the same row.

    Do not hesitate to write me back if you have more questions.

    All the best,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. ewart
    ewart avatar
    221 posts
    Member since:
    Jan 2007

    Posted 21 Nov 2008 Link to this post

    Huh?  Sorry perhaps my question wasn't clear as we're talking at cross purposes - I shall elaborate.   What I want to know is "How to get the command column name" from within the following event:

    private void myGrid_CommandCellClick(object sender, EventArgs e) 
          { 
             GridCommandCellElement gCommand = (sender as GridCommandCellElement); 
     
             if( gCommand.ColumnIndex == 11 ) 
                 // code..
          } 
     

    Why is because ColumnIndex changes everytime someone re-orders the columns.  Ideally I'd use the command column name, something like e.g.

    private void myGrid_CommandCellClick(object sender, EventArgs e) 
          { 
             GridCommandCellElement gCommand = (sender as GridCommandCellElement); 
     
             if( gCommand.ColumnName == "cmdEdit" ) 
                 // code..

             if( gCommand.ColumnName == "cmdDelete" ) 
                // code..
          } 
     
    I feel a bit sheepish about not being able to find the relevant property in the debug window (and there is basically nothing on "reorder" in the documentation) - but I know it must be there somewhere otherwise you'd have no way of handling re-ordered columns, I just can't figure it out!

    cheers
      ewart
  6. Nick
    Admin
    Nick avatar
    767 posts

    Posted 24 Nov 2008 Link to this post

    Hello ewart,

    Thank you for contacting me back.

    You can use the column header text:

    gCommand.ColumnInfo.HeaderText 

    Do not hesitate to contact me back if you have more questions.

    Kind regards,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Support@silverbear.com
    Support@silverbear.com avatar
    3 posts
    Member since:
    Jul 2010

    Posted 03 Dec 2014 Link to this post

    - He was actually after:gCommand.ColumnInfo.Name
Back to Top