none
How to display Emtpy to binded control? RRS feed

  • Question

  • Hi all,

    Let say I have a Staff table, and have a Staff Searching Form to show all the Staff's detail fields if some staff record is found. All the controls those for display staff detail are using Binding method. For examples,

    List<Staff> staffList; // All the staffs records stored here
    ...
    Binding binding = new Binding("Text", staffList, "staff_name"); // Bind staff record's field one by one
    txtStaffName.DataBindings.Add(binding);

    Binding binding = new Binding("Text", staffList, "staff_tel"); // Bind again....
    txtStaffTel.DataBindings.Add(binding);
    ...
    CurrencyManager cmStaff = this.BindingContext[staffList];  // "this" is the Form control
    int position = FindStaff ( "John" );
    cmStaff.Position = position; // Point to the found record

    All works well if a Staff record is found. But when the Staff record is not found, my "FindStaff ( )" method will return -1. In this time I don't know how to do to let the Staff Detail controls leave blank.

    I found that CurrencyManager.Position doesn't accept -1, and I don't want to un-bind everythings to let display Empty Detail.

    So how can I do that?

    Thank you very much.

    Best regards,
    Diviner.
    Wednesday, September 3, 2008 12:16 PM

All replies