滚动浏览datarepeater重新排列按钮

时间:2018-10-18 14:40:21

标签: c# forms datarepeater

因此,我有一个数据中继器,其中包含来自数据源的一些静态数据,但是我也有3个按钮,根据数据中继器项,它们的行为应有所不同。在数据中继器首次加载时,它会按预期执行所有操作,但是当我开始快速滚动浏览数据中继器中的项目时,按钮之间会发生变化,有没有办法解决此问题,例如仅让中继器绘制其项目一旦。我设置按钮的方式如下

private void NotificationdataRepeater_DrawItem(object sender, Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs e)
    {
            //Here we asign specific functions to the buttons depending on which type of notification
            string type = "";
            string subject = "";
            for (int i = e.DataRepeaterItem.Controls.Count - 1; i >= 0; i--)
            {
                Control c = e.DataRepeaterItem.Controls[i];
                if (c.Name.Contains("name"))
                {
                    type = c.Text;
                    count++;
                }
                if (c.Name.Contains("sub"))
                {
                    subject = c.Text;
                    count++;

                }
                if (c.Text == "button1")
                {
                    if (type == "Afhaalkast")
                    {
                        c.Visible = false;
                        count++;

                    }
                    if (type == "Versie")
                    {
                        c.Visible = false;
                        count++;

                    }
                    if (type == "Recept Locatie")
                    {
                        c.Visible = false;
                        count++;

                    }
                    if (type.ToUpper().Contains("BEZORGING"))
                    {
                        c.Text = "Verplaats naar morgen";
                        c.Visible = true;
                        c.Click += (s, ex) =>
                        {
                            DateTime VolgendeDag = DateTime.Today.AddDays(1);
                            if (VolgendeDag.DayOfWeek == DayOfWeek.Saturday)
                            {
                                VolgendeDag.AddDays(2);
                            }
                            else if (VolgendeDag.DayOfWeek == DayOfWeek.Sunday)
                            {
                                VolgendeDag.AddDays(1);
                            }
                            char[] arr = new char[] { ' ' };
                            string[] parts = subject.Split(arr);
                            string receptnr = parts[3];
                            dbConn.UpdateBezorgingByRecept(VolgendeDag, receptnr, false, null, parts[7], parts[10], false);
                            dbConn.voegHistorieToeString(receptnr, "Bezorging verplaatst naar " + VolgendeDag.ToString("dd-MM-yyyy"));
                            setData();
                        };
                        count++;

                    }
                    if (type.ToUpper().Contains("OUDE"))
                    {
                        c.Text = "Naar afhaalkast";
                        AfhaalPanel ap = AfhaalPanel.GetInstance;
                        c.Click += (s, ex) => ap.BringToFront();
                        count++;

                    }

                }
                if (c.Text == "button2")
                {
                    if (type == "Versie")
                    {
                        c.Visible = false;
                        count++;

                    }
                    if (type == "Recept Locatie")
                    {
                        c.Text = "Open instellingen";
                        AppContainer ac = AppContainer.GetInstance;
                        c.Click += (s, ex) => ac.instellingenTab_Click(s, ex);
                        count++;

                    }
                    if (type.ToUpper().Contains("RECEPT BEZORGING"))
                    {
                        c.Text = "Plaats in afhaalkast";
                        count++;

                    }
                    if (type == "Afhaalkast" || type.ToUpper().Contains("OUDE"))
                    {
                        c.Text = "Start met opruimen";
                        OudeRecepten oudeRecepten = new OudeRecepten();
                        c.Click += (s, ex) => oudeRecepten.Show();
                        count++;

                    }

                }
                if (c.Text == "button3")
                {
                    Notification notification = null;
                    c.Text = "Negeren";
                    foreach (Notification n in notifications)
                    {
                        if (n.Name == type)
                        {
                            notification = n;
                        }
                    }
                    c.Click += (s, ex) => ignoreNotification(notification);
                    count++;

                }
                if (c.Name == "pictogram")
                {
                    if (type == "Versie")
                    {
                        PictureBox pictogram = (PictureBox)c;
                        pictogram.Image = Properties.Resources.license_key;
                        count++;

                    }
                    if (type == "Recept Locatie")
                    {
                        PictureBox pictogram = (PictureBox)c;
                        pictogram.Image = Properties.Resources.backups;
                        count++;

                    }
                    if (type.ToUpper().Contains("RECEPT BEZORGING"))
                    {
                        PictureBox pictogram = (PictureBox)c;
                        pictogram.Image = Properties.Resources.package;
                        count++;

                    }
                    if (type == "Afhaalkast")
                    {
                        PictureBox pictogram = (PictureBox)c;
                        pictogram.Image = Properties.Resources.drawer;
                        count++;

                    }
                    if (type.ToUpper().Contains("OUDE"))
                    {
                        PictureBox pictogram = (PictureBox)c;
                        pictogram.Image = Properties.Resources.broom;
                        count++;
                    }
                }

            }
        }

        }

,通知如下所示(用作数据源)

public class Notification
{
    private string name;
    public string notificationTime;
    public string notificationSubject;
    public string notificationType;


    public Notification(string notificationName, string notificationTime, string notificationSubject, string notificationType)
    {
        this.name = notificationName;
        this.notificationTime = notificationTime;
        this.notificationSubject = notificationSubject;
        this.notificationType = notificationType;
    }

    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }

    public string Time
    {
        get
        {
            return notificationTime;
        }
        set
        {
            notificationTime = value;
        }
    }

    public string Subject
    {
        get
        {
            return notificationSubject;
        }
        set
        {
            notificationSubject = value;
        }
    }

    public string NotificationType
    {
        get
        {
            return notificationType;
        }
        set
        {
            notificationType = value;
        }
    }

}

我知道我的代码不是很干净,但这不是优先事项,稍后将予以解决

0 个答案:

没有答案