Row update -> error in Telerik.Wincontrols.UI

5 posts, 0 answers
  1. Geert
    Geert avatar
    14 posts
    Member since:
    Feb 2009

    Posted 06 Jan 2011 Link to this post

    Hello,

    I've a simple problem which I can't solve. In my C# Office application, the user can input a username and password. After he has saved the data he will be able to change the values.

    This is where it goes wrong.
    try
                   {
                       DataRow[] platformRow = dsPlatformsxml.Tables[0].Select("ID = '"+txtID.Text.ToString()+"'");
                       DataRow drUpdate = platformRow[0];
                       drUpdate[2] = txtUsername.Text.ToString();                                      
                   }
                   catch (Exception ex)
                   {
                       string test = ex.Message;
                   }

    At this line drUpdate[2] = txtUsername.Text.ToString(); the system goed to the catch section and this is the stacktrace in Telerik.Wincontrols.UI.

    at Telerik.WinControls.UI.SelfReferenceDataBinding.UpdateItem(Int32 index)
       at Telerik.WinControls.UI.SelfReferenceDataBinding.dataManager_ListChanged(Object sender, ListChangedEventArgs e)
       at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
       at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
       at System.Data.DataView.OnListChanged(ListChangedEventArgs e)
       at System.Data.DataView.IndexListChanged(Object sender, ListChangedEventArgs e)
       at System.Data.DataView.IndexListChangedInternal(ListChangedEventArgs e)
       at System.Data.DataViewListener.IndexListChanged(ListChangedEventArgs e)
       at System.Data.Index.<OnListChanged>b__2(DataViewListener listener, ListChangedEventArgs args, Boolean arg2, Boolean arg3)
       at System.Data.Listeners`1.Notify[T1,T2,T3](T1 arg1, T2 arg2, T3 arg3, Action`4 action)
       at System.Data.Index.OnListChanged(ListChangedEventArgs e)
       at System.Data.Index.OnListChanged(ListChangedType changedType, Int32 newIndex, Int32 oldIndex)
       at System.Data.Index.RecordStateChanged(Int32 oldRecord, DataViewRowState oldOldState, DataViewRowState oldNewState, Int32 newRecord, DataViewRowState newOldState, DataViewRowState newNewState)
       at System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2)
       at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Int32 position, Boolean fireEvent, Exception& deferredException)
       at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean fireEvent)
       at System.Data.DataRow.SetNewRecord(Int32 record)
       at System.Data.DataRow.EndEdit()
       at System.Data.DataRow.set_Item(DataColumn column, Object value)
       at System.Data.DataRow.set_Item(Int32 columnIndex, Object value)
       at WordAddIn.SaveForm.btnChangePlatformOk_Click(Object sender, EventArgs e) in C:\.NET Projecten\Word Add-in\WordAddIn\WordAddIn\FormSave\SaveForm.cs:line 634


    Does anybody knows what the cause is for this error, I'm trying to solve it for 2 hours, but can't find why "Object reference not set to an instance of an object is showing"...
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 06 Jan 2011 Link to this post

    Hello,

    Whilst I can't tell you exactly where the issue is, I can say that it seems to be with your datasource and not the telerik controls. I would advise looking into your datasource more closely to identify the issue, and also confirm this by substituting your datasource with a simple generic list or similar to try it out.
    Regards,
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Jan 2011 Link to this post

    Hello,

    How did this go? If it helped, please remember to mark as answer. If you need more assistance, please let me know
    thanks
    Richard
  5. Geert
    Geert avatar
    14 posts
    Member since:
    Feb 2009

    Posted 07 Jan 2011 Link to this post

    Hello Richard,

    I found a solution. The reason is that the datasource is bound to a treeview. Because this is an active connection, I can't update the row in the same threat.

    With the following code I solved the problem.
    DataTable dtTable = dsPlatformsxml.Tables[0].Copy();
      
                        DataRow[] drRow = dtTable.Select("ID = '" + txtID.Text.ToString() + "'");
                        drRow[0]["User"] = txtUsername.Text.ToString();
                        drRow[0]["Password"] = TamperProofStringEncode(txtPassword.Text.ToString(), "encryptstring");
      
                        if (chkSavePc.Checked)
                        {
                            drRow[0]["SaveSettings"] = "true";
                        }
                        else
                        {
                            drRow[0]["SaveSettings"] = "false";
                        }
                        dsPlatformsxml.Tables.RemoveAt(0);
                        dsPlatformsxml.Tables.Add(dtTable);
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Jan 2011 Link to this post

    Hello,

    Im glad you have this sorted. If you need anyhing further just let me know
    Richard
Back to Top
UI for WinForms is Visual Studio 2017 Ready