4

I have created a property to a custom windows form I made.

private List<object> values;

public List<object> Values
{
    get
    {
       return values;
    }
    set
    {
       values = value;
    }
}

It shows up in the property window on designer just fine. I go to the property value field and the button with '...' three dots shows. I click on the button and the window with which allows me to add items to list appears. I add them and click ok. No erro appears, but the items have not been saved.

My question is how to properly set this up so I can set the List<object> items in the property windows while in design?


Multiple output calculation SUMPRODUCT (Google Sheets)

I'm working on a hotel booking calendar tool where I need to calculate the average price per night for reservations that appear between 2 arbitrary search dates. Things to consider:

  • the bookings are recorded using a check-in date and a check-out date
  • together with a single booking price (everything is on the same row)
  • check-out date counts as vacant since the room will be empty by the daily check-in time
  • we only want the booking value of the days that fall between the search 2 dates
  • to be clear, bookings can extend paste the 1st & 2nd search dates, but we will ignore the daily values for those days beyond the date extremities
  • I really want to do this using formulas, not code

I've been playing with a SUMPRODUCT formula all day, and have got pretty close to the desired result - this particular rendition only captures the total number of rooms filled during the period, but modifying it to return the values isn't a problem:

=ARRAYFORMULA(SUMPRODUCT(GTE(Bookings_EndDate,ReportExec_StartDate+1),  LTE(Bookings_StartDate,ReportExec_EndDate+0),IF((Bookings_StartDate<=ReportExec_StartDate)*(Bookings_EndDate>=ReportExec_EndDate),((ReportExec_EndDate-ReportExec_StartDate+1)),IF(Bookings_StartDate<ReportExec_StartDate,Bookings_EndDate-ReportExec_StartDate,IF(Bookings_EndDate>ReportExec_EndDate,(ReportExec_EndDate+1)-Bookings_StartDate,0)))))

What I think is the problem here, is that the array calculation only outputs the condition met by the first IF(), so I'm pretty sure this is the wrong approach. Quick orientation of the named ranges:

  • ReportExec_StartDate / ReportExec_EndDate = search date 1 / search date 2
  • Bookings_StartDate / Bookings_EndDate = columns containing check-in / check-out dates

First IF() condition hunts out all the bookings that extend up to/past the search dates 2nd nested IF() hunts bookings that extend only before the 1st search date 3rd nested IF() hunts bookings that extend only beyond the 2nd search date

In Excel this would be easier, but Google is a new toy for me - any thoughts welcome!

4

2 回答 2

1

谢谢键盘P。我将我的代码更改为您建议的内容

私有列表<object>值 = 新列表<object>();

公共列表<object>值 { 获取 { 返回值;} 设置 { 值 = 值;} }

它完全按照我想要的方式工作。

如果有人需要,需要注意一件事。<CustomClass>如果您使用的是 List而不是 List 之类的自定义类<object>。在“CustomClass”定义中这样做

[System.Serializable] public class CustomClass { ...... }

否则,当您尝试通过属性窗口将项目添加到列表时会出错。

另一种方法是将列表更改<CustomClass>为 CustomClass[]

私有 CustomClass[] 值;

公共自定义类 [] 值 { 获取 { 返回值;} 设置 { 值 = 值 } }

这第二种方法我不需要在 CustomClass 定义的开头添加 [System.Serializable]。

我希望这对某人有所帮助。

于 2013-07-06T18:34:02.233 回答
1

在您的 Form1.Designer.cs 中,List像这样手动实例化

this.Values = new List<object>();

添加项目后,Form1.Designer.cs文件将正常重新创建,但上面的行将替换为

this.Values = ((System.Collections.Generic.List<object>)(resources.GetObject("$this.Values")));

或者,在声明列表时实例化它。

private List<object> values = new List<object>();

public List<object> Values
{
    get
    {
        return values;
    }
    set
    {
        values = value;
    }
 }
于 2013-07-06T18:02:27.647 回答