小编BT.*_*BT.的帖子

Windows窗体中的RadioButton绑定与INotifyPropertyChanged?

我试图将一些RadioButtons绑定到类中的布尔值,然后启用/禁用表单上的其他元素.例如:

x radioButton1
    x checkBox1
x radioButton2
    x checkBox2
Run Code Online (Sandbox Code Playgroud)

我想只在选择了radioButton1时启用checkBox1,同样也支持radioButton2和checkBox2.

当我尝试绑定这些时,需要两次单击才能更改RadioButton选择.似乎绑定的顺序导致逻辑问题.

这是代码,显示了这一点.表单只有两个默认名为RadioButtons和两个CheckBoxes.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        BindingSource bindingSource = new BindingSource(new Model(), "");

        radioButton1.DataBindings.Add(new Binding("Checked", bindingSource, "rb1Checked", true, DataSourceUpdateMode.OnPropertyChanged));
        radioButton2.DataBindings.Add(new Binding("Checked", bindingSource, "rb2Checked", true, DataSourceUpdateMode.OnPropertyChanged));

        checkBox1.DataBindings.Add(new Binding("Enabled", bindingSource, "cb1Enabled", true, DataSourceUpdateMode.OnPropertyChanged));
        checkBox2.DataBindings.Add(new Binding("Enabled", bindingSource, "cb2Enabled", true, DataSourceUpdateMode.OnPropertyChanged));
    }
}

public class Model : INotifyPropertyChanged
{
    private bool m_rb1Checked;
    public bool rb1Checked
    {
        get { return m_rb1Checked; }
        set
        {
            m_rb1Checked = value;
            NotifyPropertyChanged("cb1Enabled"); …
Run Code Online (Sandbox Code Playgroud)

c# winforms

4
推荐指数
1
解决办法
5477
查看次数

RavenDB:异步SaveChanges影响以后的更新?

作为学习RavenDB的一部分,我试图根据我每晚下载的列表更新一组股票.

我有一个Stock类,其中Id是股票代码:

public class Stock
{
    public string Id { get; set; }
    public StockStatus Status { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用此算法同步列表:

  1. 更新或插入现在下载的所有股票为"StillActive".
  2. 任何上次状态为"活跃"的股票意味着他们不在更新中,需要"删除".
  3. 所有股票仍然"StillActive"成为新的"活跃"股票.

这是实施:

List<Stock> stocks = DownloadStocks();

using (var session = RavenContext.Store.OpenSession())
{
    foreach (Stock stock in stocks)
    {
        stock.Status = StockStatus.StillActive;
        session.Store(stock);
    }

    session.SaveChanges();

    session.PatchUpdateCutoffNow("Stocks/ByStatus", "Status:Active", "Status", StockStatus.Deleted);
    session.PatchUpdateCutoffNow("Stocks/ByStatus", "Status:StillActive", "Status", StockStatus.Active);
}
Run Code Online (Sandbox Code Playgroud)

PatchUpdateCutoffNow是一个扩展方法,它使用Cutoff现在执行UpdateByIndex:

public static void PatchUpdateCutoffNow(this IDocumentSession session, string indexName, string query, string name, object val)
{
    session.Advanced.DatabaseCommands.UpdateByIndex(indexName, 
        new IndexQuery() { Query = query, …
Run Code Online (Sandbox Code Playgroud)

c# nosql ravendb

0
推荐指数
1
解决办法
1015
查看次数

标签 统计

c# ×2

nosql ×1

ravendb ×1

winforms ×1