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

Command Column Click Event

6 Answers 905 Views
GridView
This is a migrated thread and some comments may be shown as answers.
KUMARAN
Top achievements
Rank 1
KUMARAN asked on 25 Apr 2015, 09:45 AM

I want get the some column detail by clicking the command button.

Ex: If a had price 10 as default and when i click command button the price will be updated as 12.

How can do this by using programmatically.

 Thanks in advance.

Note: VB Coding

6 Answers, 1 is accepted

Sort by
0
KUMARAN
Top achievements
Rank 1
answered on 25 Apr 2015, 09:49 AM
I will be glad if you send a sample attachment in vb.
  
0
Joe
Top achievements
Rank 2
answered on 25 Apr 2015, 03:36 PM

This will do what I *think* you are asking for, just a sample but should point the way:

Private Sub Form1_Load( sender As Object,  e As EventArgs) Handles MyBase.Load
    
       'create a command column (button)
       Dim commandColumn As New GridViewCommandColumn()
       'name it so we cah check for it later
       commandColumn.Name = "change"
       commandColumn.UseDefaultText = False
       commandColumn.HeaderText = "Command"
       'add the button
       RadGridView1.MasterTemplate.Columns.Add(commandColumn)
       'add a column to hold price info
       Dim priceColumn As New GridViewTextBoxColumn()
       priceColumn.Name = "price"
       priceColumn.HeaderText = "Price"
       RadGridView1.MasterTemplate.Columns.Add(priceColumn)
       'Adds three rows of data to the grid
       radgridview1.rows.add("Add","10")
       radgridview1.rows.add("Add","13")
       radgridview1.rows.add("Add","15")
 
 
   End Sub

 then in the events of the grid box choose the CellClick event and put something like this:

Private Sub RadGridView1_CellClick( sender As Object,  e As GridViewCellEventArgs) Handles RadGridView1.CellClick
        'everytime a cell is clicked this will run, check to see if they clicked the column named change
        if e.Column.name = "change"
            'if so then take the current row and replace the value with whatever is typed in the textbox1
            RadGridView1.mastertemplate.currentrow.cells("price").value = textbox1.text
 
        End If
End Sub

 

Let me know if you need clarification.

Joe

 

0
Accepted
Joe
Top achievements
Rank 2
answered on 25 Apr 2015, 03:38 PM

Sorry...I formatted the code as c#...here is it formatted correctly:

 

  Private Sub Form1_Load( sender As Object,  e As EventArgs) Handles MyBase.Load
     
        'create a command column (button)
        Dim commandColumn As New GridViewCommandColumn()
        'name it so we cah check for it later
        commandColumn.Name = "change"
        commandColumn.UseDefaultText = False
        commandColumn.HeaderText = "Command"
        'add the button
        RadGridView1.MasterTemplate.Columns.Add(commandColumn)
        'add a column to hold price info
        Dim priceColumn As New GridViewTextBoxColumn()
        priceColumn.Name = "price"
        priceColumn.HeaderText = "Price"
        RadGridView1.MasterTemplate.Columns.Add(priceColumn)
        'Adds three rows of data to the grid
        radgridview1.rows.add("Add","10")
        radgridview1.rows.add("Add","13")
        radgridview1.rows.add("Add","15")
 
 
    End Sub
 
 
 
Private Sub RadGridView1_CellClick( sender As Object,  e As GridViewCellEventArgs) Handles RadGridView1.CellClick
        'everytime a cell is clicked this will run, check to see if they clicked the column named change
        if e.Column.name = "change"
            'if so then take the current row and replace the value with whatever is typed in the textbox1
            RadGridView1.mastertemplate.currentrow.cells("price").value = textbox1.text
 
        End If
End Sub

 

0
KUMARAN
Top achievements
Rank 1
answered on 26 Apr 2015, 09:18 AM
Thanks for the Reply.How to Edit and Delete Forum threads, in case if i made a mistake in my Questions.
0
Joe
Top achievements
Rank 2
answered on 26 Apr 2015, 11:02 AM

Hello;

I don't think you can on here (like on Stackoverflow?)  Also, I would have uploaded the project but this does not allow upload of anything except pictures.

Let me know if this works out for you.

Good luck and happy coding!

Joe

0
Hristo
Telerik team
answered on 29 Apr 2015, 02:29 PM
Hello guys,

@Joe, thank you for sharing your solution with our community. Your Telerik points are updated accordingly. 

@Kumaran, users are not allowed to modify their posts. More detailed information on using our forum you can find here: Important Information on Using the Telerik Forums

Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

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