none
Releasing of row changed with custom datacolumn RRS feed

  • Question

  • Hello. I have a question for that i realy cant find an answer myself.

    I have a dataset with some datatables.

    One of the datatables has a column with datatype System.Object

    The rows of this table are filled with instances of datatype A

    This custom datatype A implements the IChangeTracking interface as suggested in msdn.

    If i do changes in an instance located in a datarow i do not get a row changed event fired, nor the row is marked as modified if i get the rowstate.

    Maybe somebody can tell me where is my point of misunderstanding the underlying concept.

    What more do i need to do?

    Thanks!

    PS: for some reasons i cant directly set the datatype of the column to type A

     

    Edit: I could solve the problem with the rowstate by setting the column.datatype to type System.ComponentModel.IChangeTracking. Now that is working great.

    But how i can release the events rowchanged/columnchanged by the custom Object A?

     

    Thursday, March 10, 2011 1:18 PM

Answers

  • Hello Fraggel,

     

    Welcome to the MSDN Forum and thanks for posting here.

    According to your description, I think if you have any time could you please show us some code about releasing the events rowchanged/columnchanged ? Maybe we can help to find the reason.

    Another, the following code tell us about the row_changed event:

    private static void DataTableRowChanged()
        {
            DataTable custTable = new DataTable("Customers");
            // add columns
            custTable.Columns.Add("id", typeof(int));
            custTable.Columns.Add("name", typeof(string));
            custTable.Columns.Add("address", typeof(string));

            // set PrimaryKey
            custTable.Columns[ "id" ].Unique = true;
            custTable.PrimaryKey = new DataColumn[] { custTable.Columns["id"] };

            // add a RowChanged event handler for the table.
            custTable.RowChanged += new DataRowChangeEventHandler(Row_Changed);


            // add ten rows
            for(int id=1; id<=10; id++)
            {
                custTable.Rows.Add(
                    new object[] { id, string.Format("customer{0}", id),
                    string.Format("address{0}", id) });
            }

            custTable.AcceptChanges();

            // change the name column in all the rows
            foreach(DataRow row in custTable.Rows)
            {
                row["name"] = string.Format("vip{0}", row["id"]);
            }

        }

        private static void Row_Changed(object sender, DataRowChangeEventArgs e)
        {
            Console.WriteLine("Row_Changed Event: name={0}; action={1}",
                e.Row["name"], e.Action);
        }

     See also:

    http://stackoverflow.com/questions/2090511/ado-net-question-how-can-i-update-a-column-in-a-row-of-a-datatable-with-rowchan

    I hope this can help you.

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Sunday, March 13, 2011 7:58 AM
    Moderator

All replies

  • Hello Fraggel,

     

    Welcome to the MSDN Forum and thanks for posting here.

    According to your description, I think if you have any time could you please show us some code about releasing the events rowchanged/columnchanged ? Maybe we can help to find the reason.

    Another, the following code tell us about the row_changed event:

    private static void DataTableRowChanged()
        {
            DataTable custTable = new DataTable("Customers");
            // add columns
            custTable.Columns.Add("id", typeof(int));
            custTable.Columns.Add("name", typeof(string));
            custTable.Columns.Add("address", typeof(string));

            // set PrimaryKey
            custTable.Columns[ "id" ].Unique = true;
            custTable.PrimaryKey = new DataColumn[] { custTable.Columns["id"] };

            // add a RowChanged event handler for the table.
            custTable.RowChanged += new DataRowChangeEventHandler(Row_Changed);


            // add ten rows
            for(int id=1; id<=10; id++)
            {
                custTable.Rows.Add(
                    new object[] { id, string.Format("customer{0}", id),
                    string.Format("address{0}", id) });
            }

            custTable.AcceptChanges();

            // change the name column in all the rows
            foreach(DataRow row in custTable.Rows)
            {
                row["name"] = string.Format("vip{0}", row["id"]);
            }

        }

        private static void Row_Changed(object sender, DataRowChangeEventArgs e)
        {
            Console.WriteLine("Row_Changed Event: name={0}; action={1}",
                e.Row["name"], e.Action);
        }

     See also:

    http://stackoverflow.com/questions/2090511/ado-net-question-how-can-i-update-a-column-in-a-row-of-a-datatable-with-rowchan

    I hope this can help you.

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Sunday, March 13, 2011 7:58 AM
    Moderator
  • But how i can release the events rowchanged/columnchanged by the custom Object A?

    Not exactly sure what you mean by this ... can you elaborate?


    ~~Bonnie Berent [C# MVP]

    geek-goddess-bonnie.blogspot.com
    Sunday, March 20, 2011 1:22 AM