none
Problems with Event Args RRS feed

  • Question

  • Hi

    I have a dataSet(dataServer) with a table called Vehicles. I want to know when a this table is changed. Like adding new row or a row changed.


     interfaceIL.dataServer.Vehicles.TableNewRow += new DataTableNewRowEventHandler(Vehicles_TableNewRow);
    ...

    interfaceIL.dataServer.Vehicles.VehiclesRowChanged += new DataSetServer.VehiclesRowChangeEventHandler(Vehicles_VehiclesRowChanged);

    ...

    void Vehicles_TableNewRow(object sender, DataTableNewRowEventArgs e)



     void Vehicles_VehiclesRowChanged(object sender, DataSetServer.VehiclesRowChangeEvent e)
    {
    AppendVehicleToListView(e.Row);
    }

    void Vehicles_TableNewRow(object sender, DataTableNewRowEventArgs e)
    {

    AppendVehicleToListView(e.Row);



    }
    private void AppendVehicleToListView(DataRow r)
    {



    string[] elements = new string[3];

    elements[0] = r[0].ToString();
    elements[1] = r[1].ToString();
    elements[2] = r[2].ToString();

    ListViewItem lvItem = new ListViewItem(elements);

    listViewVehicles.Items.Add(lvItem);
    listViewVehicles.EndUpdate();

    }



    Problem: TableNewRow doesn't work. Second, in RowChanged, listing in listview give the argument two time. As example if i add a element, in listview it adds 2 elements. In the real dataServer.Vehicle is only one element. What i'm doing wrong with these events?

    I think the elemente e DataTableNewRowEventArgs e gives us the added row, and the RowChangedEventArgs e the changed Row.

    Regards

    Friday, June 12, 2009 6:03 PM

Answers

  • I don't know if this would be an option for you ... but I found the easiest way to do this is to put the data from the DataTable into a BindingList<T>. It then produces the events you need as you add/remove/update items in the list.
    www.insteptech.com
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    • Proposed as answer by Rudedog2 Friday, June 12, 2009 6:24 PM
    • Marked as answer by Bin-ze Zhao Thursday, June 18, 2009 5:32 AM
    Friday, June 12, 2009 6:16 PM