bool and objects

I have an collection of objects(arraylist)...in my list is want to check to see if properties within my arraylist have changed by using a _IsDirty flag...but i get an error saying cannot convert object to bool can anyone help me out here

[code languge="C#"]

for(int x = 0; x < ArrayList.Count; x++)

{

if(Convert.ToBoolean(Arraylist[x]) == this._IsDirty)

{

}

[/code]

how should this be




Answer this question

bool and objects

  • J.B. III

    Do i need to cast the loop varible to the type of control that i am using and then check and see if any of the objects have changed within that form

    How it works is that i have a form with a user control that creates panel's at runtime....these panel are shipper, vendor, consignee panels...when one of the panels is created based on what button you click on the user control...there are three buttons "insert vendor" "insert shipper" and "insert consignee"...when there are created there is a button on the panel itself that u click and it brings up another form with information be be filled in pertaining to which ever control u just created...all of the controls you create are added to an ArrayList to keep up with the ordering...but i need to know if any of the values have changed within the forms on the panels that get created by clickin those buttons....



  • Gurmeet

    what type of objects are you storing in the arraylist you need to get that object and then check its property, currently you are not doing this. So what object types are you storing

  • PsyCadelik

    this is how i am doing it right now and it seems like this way will work


    // for(int x = 0; x < Legs.Count; x++)
    // {
    // if(((Tracking.BusinessObjects.OrderLegDetail)Legs[x]).IsDirty)
    // {
    // if(((Tracking.BusinessObjects.OrderLegDetail)Legs[x]).ChildType == "Stop")
    // {
    // ((Tracking.BusinessObjects.StopOrderLegDetail)x).Save();
    // }
    // }
    // }
    // }
    // }



  • Dee_dotnet_79

    ok, try something like this:

     

    if (((Tracking.UI.Controls.OrderLegData)tempOrderManifest[index]).IsDirty) { .... do stuff .... }

    you maybe better to use generics, a strongly typed collection of objects without having to do this casting stuff. Example:

     

    List<Tracking.UI.Controls.OrderLeg> theCollection = new List<Tracking.UI.Controls.OrderLeg>();

    theCollection.Add(yourObject);

     

    next time you need to check an object in the collection:

    theCollection[index].IsDirty; //for example



  • JV Chevy

    no it doesn't :-) it was introduced in .NET 2.0

  • Emre &amp;#199;etinkaya

    yes that looks ok. A better way would be to use the Generic List<> collection as you don't have to do any casting as you are right now....the Generic List<> will hold a type of an object (Tracking.BusinessObjects.OrderLegDetail in this case) which means you don't need to do any casting and can access an object of that type and access its properties normally, without casting.

    Example:

    List<Tracking.BusinessObjects.OrderLegDetail> theCollection = new List<Tracking.BusinessObjects.OrderLegDetail>();

     

    this.theCollection.Add(OrderLegDetailObject);

    //time comes to iterate:

     

    foreach(Tracking.BusinessObjects.OrderLegDetail currentObject in this.theCollection)

    {

       if (currentObject.IsDirty)

       {

          //do stuff

       }

    }



  • battlex

    I am storing Custom Control object types...everytime i create one i add to the the array list

  • shmulik_segal

    you could but that would be overkill. you can use a generic to hold the objects then access the object in question and check the objects property as this is what it is required to see if some other event somewhere has triggered the property to be changed from some where else, then when "finalizing" as what the OP is doing (Checking) - would like to see what the state of each object's isDirty property is reporting

  • Soby

    what type is the class though Can you show us how you create and add this class

  • zwp

    A better solution is to create your own class inheriting from some structure and put a property IsDirty out there and you change its value whenever items in collection are added, removed or modified. You dont need to put dirty byte itself in Array.

    I hope this will help in choosing a right direction of doing things!

    Best Regards,



  • allpdoff

    Tracking.UI.Controls.OrderLegData _OrderLegData = new Tracking.UI.Controls.OrderLegData();

    Tracking.BusinessObjects.StopOrderLegDetail newStopOrderLegDetail = .Tracking.BusinessObjects.StopOrderLegDetail.GetNewStopDetail();

    newStopOrderLegDetail.Index = tempOrderManifest.Count;

    _OrderLegData.OrderLegDetail = (Tracking.BusinessObjects.OrderLegDetail)newStopOrderLegDetail;

    _OrderLegData.Left = 0;

    _OrderLegData.Top = (_OrderLegData.OrderLegDetail.Index * (_OrderLegData.Height + _VerticalSpacing)) + _InitialTop + this.pnlDataContainer.AutoScrollPosition.Y;

    _OrderLegData.txtname.Text = "Consignee";

    _OrderLegData.OnRemoveItems +=new Tracking.UI.Controls.OrderLegData.RemoveItems(_OrderLegData_OnRemoveItems);

    this.pnlDataContainer.Controls.Add(_OrderLegData);

    tempOrderManifest.Add(_OrderLegData.OrderLegDetail); <- add the item to the arraylist



  • shax

    too bad i am using 1.1 and i dont think it has Generics or does it

  • bool and objects