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

Update problems

3 Answers 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
timtom
Top achievements
Rank 1
timtom asked on 18 Sep 2008, 05:27 PM
Hi :o)

I am having a strange problem when updating new added records in the grid.
I use the code below to cycle through the grid and change the ClientId to p_ClientId which works fine. This is why the msgbox is there to check the value which changes to the value in p_ClientId as expected. You can also see this reflected in the grid itself as the column is visible.

For i = 0 To Me.RadGridView1.RowCount - 1
     Me.RadGridView1.Rows(i).Cells("ClientId").Value = p_ClientId
     MsgBox(Me.RadGridView1.Rows(i).Cells("ClientId").Value)
Next

The problems comes when I save the grid to the database using the code below.

Me.ClientsSupportRequiredBindingSource.EndEdit()
Me.ClientsSupportRequiredTableAdapter.Update(Me.Clients)

The database only reflects the change in the last record. The others are added with a NULL in ClientId. This only affect this one field and only when adding a new record. If you update other fields directly using the grid then they update correctly. 

Thank you so much for your help

Tim

3 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 23 Sep 2008, 01:09 PM
Hi Tim,

When you loop through Rows and change values from the API, the EndEdit() is not called for rows. Rather, you can use the following code snippet:

For i As Integer = 0 To Me.RadGridView1.RowCount - 1 
    DirectCast(Me.RadGridView1.Rows(i).DataBoundItem, IEditableObject).BeginEdit() 
    Me.RadGridView1.Rows(i).Cells("ClientId").Value = p_ClientId 
    DirectCast(Me.RadGridView1.Rows(i).DataBoundItem, IEditableObject).EndEdit() 
    MsgBox(Me.RadGridView1.Rows(i).Cells("ClientId").Value) 
Next 

I hope this was helpful. If you have additional questions, please contact us.

 
Kind regards,
Julian Benkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Per Holmqvist
Top achievements
Rank 2
answered on 06 Nov 2008, 02:59 PM
I have a similar problem, I try to create a search and replace function

My grids datasource is NWProductsBindingSource

In form load I have
   Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
        'TODO: This line of code loads data into the 'NWProducts.Products' table. You can move, or remove it, as needed.  
        Me.ProductsTableAdapter.Fill(Me.NWProducts.Products)  
    End Sub 
 


My updatefunction is like
    Private Sub RadButton2_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles RadButton2.Click  
        RadGridView1.GridElement.BeginUpdate()  
        For i As Integer = 0 To Me.RadGridView1.RowCount - 1  
            DirectCast(Me.RadGridView1.Rows(i).DataBoundItem, IEditableObject).BeginEdit()  
            If InStr(Me.RadGridView1.Rows(i).Cells("QuantityPerUnit").Value, searchtext.Text) > 0 Then 
                Me.RadGridView1.Rows(i).Cells("QuantityPerUnit").Value = Replace(Me.RadGridView1.Rows(i).Cells("QuantityPerUnit").Value, searchtext.Text, replacetext.Text)  
            End If 
            DirectCast(Me.RadGridView1.Rows(i).DataBoundItem, IEditableObject).EndEdit()  
        Next 
        RadGridView1.GridElement.EndUpdate()  
        Me.ProductsTableAdapter.Update(RadGridView1.DataSource)  
    End Sub 


Any idea what to exchange the RadGridView1.Datasource with so the TableAdapter.update() works?
Or is the an automaticupdatefunction in FormGrid like it is in Ajax Grid?

Another detail, how can I set the grid to occupy 100% width/height? If I try to set values i can't set percentage, only fixed int. :(
Regards Pelle
0
Julian Benkov
Telerik team
answered on 10 Nov 2008, 03:58 PM
Hi Per Holmqvist,

To update your Products table you must call:

Me.ProductsTableAdapter.Update(Me.NWProducts.Products)   

All your other code seems to be fine.

To change the size of columns you can use the BestFit() method. To change the size of the rows you can use the RowHeight property of GridTableElement.

I hope this was helpful. If you continue to have a problems, please contact us.

Sincerely yours,
Julian Benkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
timtom
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Per Holmqvist
Top achievements
Rank 2
Share this question
or