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

Update bound column programmatically

6 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 22 Jun 2012, 07:16 PM
A simplified explanation of what I need...

I have a GridView control bound to a dataset.  Column A (editable) and Column B (Read Only).

When a user changes Column A, a calculation is run in the code behind and Column B changes.

It seems simple enough, but I'm having trouble getting values in my GridView to change through code.  Can someone please post a simple example of how to do this?

Thank you in advance.

6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 25 Jun 2012, 07:20 AM
Hi,

Have you tried to use an approach like this one:

myGrid.Items.EditItem(itemToEdit);
itemToEdit.ColumnA= DoChanges();
myGrid.Items.CommitEdit();

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Ben
Top achievements
Rank 1
answered on 25 Jun 2012, 03:26 PM
Thank you for your reply.  I need some further explanation.  Can you post some sample code that further explains how I update the contents of the cell?  I'm thinking I would use the CurrentCellChanged event.  Is that correct?  Please look at my example below and give me some feedback.  Thank you.

 

Private Sub gvComp_CurrentCellChanged(sender As Object, e As Telerik.Windows.Controls.GridViewCurrentCellChangedEventArgs) Handles gvComp.CurrentCellChanged
    Try
        If e.OldCell Is Nothing Then Exit Sub
        If Not e.OldCell.ParentRow Is Nothing Then
              
            gvComp.Items.EditItem(e.OldCell.ParentRow)
              ' What's next ?
            gvComp.CommitEdit()
        End If

 

0
Dimitrina
Telerik team
answered on 25 Jun 2012, 03:44 PM
Hello,

 I would suggest you binding the ItemsSource of the GridView to the DefaultView of the DataTable instead because the DataRowView is capable of sending notifications. That way the values in the cells should be automatically updated once the change on the underlying data is done.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Ben
Top achievements
Rank 1
answered on 25 Jun 2012, 03:51 PM
I'm afraid I can't do that.  There are some security concerns with the data I am dealing with.  I need to treat this like a disconnected dataset. 

There must be some way to simply update grid values in the code behind.  I am a new user of your tools.  Can you please show me some sample code that does this?  Thank you.
0
Accepted
Dimitrina
Telerik team
answered on 27 Jun 2012, 03:54 PM
Hello,

 I have attached the sample project suggested from my colleague in your another thread so that the whole community could benefit from it.

It illustrates a possible approach to achieve your goal. 

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Ben
Top achievements
Rank 1
answered on 27 Jun 2012, 08:52 PM
This is extremely helpful.  Thank you .
Tags
GridView
Asked by
Ben
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Ben
Top achievements
Rank 1
Share this question
or