Command button text

5 posts, 1 answers
  1. Philippe
    Philippe avatar
    25 posts
    Member since:
    Apr 2012

    Posted 13 Jan 2015 Link to this post


    Hello. I am using Telerik v2014.2.715.40

    I have an unbound grid where I replace 2 columns with CommandButton columns. One of the column is very straightfoward, but the other needs a slightly more complicated behavior.

    The column I am replacing has a Yes or No value, and I want the button to have the current value of the cell written on it. Pressing the button needs to change the textto the other value, as well as save it in the database.

    I am trying to use the initial column creation, or CellFormatting to set the button' text, but no luck.

    I am using CommandCellClick to actually change the current value as well as save it in the database, but I am having a hard time handling the object's value without getting NULLs.

    Thanks in advance.

    Creating the column:
    GridViewCommandColumn commandColumn2 = new GridViewCommandColumn();
     commandColumn2.Name = "Pertinent";
     //commandColumn2.UseDefaultText = true;
     //commandColumn2.DefaultText = "z";
     commandColumn2.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
     commandColumn2.HeaderText = "Pertinent";
     radGridDocuments.Columns.Remove("Pertinent");
     radGridDocuments.MasterTemplate.Columns.Add(commandColumn2);



  2. Philippe
    Philippe avatar
    25 posts
    Member since:
    Apr 2012

    Posted 14 Jan 2015 in reply to Philippe Link to this post

    Also, as an addition, is it possible to move down the column (read: move to the next row, excel-like) with the arrow keys, and press Spacebar to simulate a button click? This would make my users alot more efficient.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 16 Jan 2015 Link to this post

    Hello Philippe,

    Thank you for writing.

    I am sending you attached a sample project where I established a connection to a DataTable. I followed your instructions and deleted a string column having Yes or No values, then I added to the grid a GridViewCommandColumn with the text value being the value of the deleted column. You could change the values of that column in the handler of CommandCellClick event.

    As for your second question, navigation through the cells using the arrow keys is enabled by default. Changing the values of the command cells using the space bar can be accomplished by creating a CustomGridDataRowBehavior and overriding the ProcessSpaceKey method, the implementation is included in the attached project.

    I am additionally sending you a .gif file show how the grid looks on my side.

    I hope that the provided code will help. should you have further question please do not hesitate to write back.

    Regards,
    Hristo
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Philippe
    Philippe avatar
    25 posts
    Member since:
    Apr 2012

    Posted 16 Jan 2015 in reply to Hristo Link to this post

    Hello Hristo

    From your code, I found that I was lacking the following line of code in my column setup to display the datacell' value on the CommandButton:
    commandColumn2.FieldName = "Pertinent";

    As for your CustomeGridDataRowBehavior class, it works perfectly and is exactly what I needed. Another tool to add to my toolbelt! An extra kudos for the sheer simplicity of the solution.

    Many thanks and have a great day!
    -Philippe
  6. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 20 Jan 2015 Link to this post

    Hi Phillippe,

    I am glad that the proposed solution was suitable for your case. 

    Should you have further question do not hesitate to ask.

    Regards,
    Hristo
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready