This is a migrated thread and some comments may be shown as answers.

Command button text

4 Answers 175 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Philippe
Top achievements
Rank 2
Philippe asked on 14 Jan 2015, 03:50 AM

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);



4 Answers, 1 is accepted

Sort by
0
Philippe
Top achievements
Rank 2
answered on 14 Jan 2015, 02:31 PM
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.
0
Accepted
Hristo
Telerik team
answered on 16 Jan 2015, 02:58 PM
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.

 
0
Philippe
Top achievements
Rank 2
answered on 16 Jan 2015, 06:19 PM
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
0
Hristo
Telerik team
answered on 20 Jan 2015, 04:54 PM
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.

 
Tags
GridView
Asked by
Philippe
Top achievements
Rank 2
Answers by
Philippe
Top achievements
Rank 2
Hristo
Telerik team
Share this question
or