我正在从 ObservableCollection 添加和删除,但网格没有更新

发布于 2024-11-14 23:37:55 字数 3205 浏览 1 评论 0原文

我正在使用此代码来更新我的网格。它不起作用。网格未更新。我找不到代码有任何问题。这是一个帮助台应用程序。我正在尝试使用客户端上的网格更新服务器上的已关闭票证。帮助 !

public class DAL_LOADTICKETS
{
    private static string URL ="http://helpdesk.hujelabs.com/user.php/"+Login.user_id+"/query/";
    public static void/*ObservableCollection<cTicket>*/ LoadOPENTICKETS()
    {
        // Execute the query using the LINQ to XML

        var tickets = from c in XElement.Load(URL).Elements("query") select c;
        foreach (var ticks in tickets)
        {
            cTicket lTicket = new cTicket
            {
                TicketID = ticks.Element("query_id").Value,
                TicketStatus = ticks.Element("status").Value,
                TicketSubject = ticks.Element("subject").Value,
                TicketDescription = ticks.Element("description").Value,
                TicketTags = ticks.Element("tag").Value,
                TimeStamp = ticks.Element("timestamp").Value,
            };
            if (ticks.Element("status").Value == "open")
            {
                if (!Window1.OpenTicketsList.Contains(lTicket))
                {
                    Window1.OpenTicketsList.Add(lTicket);
                }
            }

            else if (ticks.Element("status").Value == "closed")
            {
                if (Window1.OpenTicketsList.Contains(lTicket))
                {
                    Console.WriteLine("VISITED BUT NOT DELETED");

                    Window1.OpenTicketsList.Remove(lTicket);
                }
            }

        }

    }
<Grid Width="756" Background="White">
                    <ListView Name="OpenReqList" HorizontalAlignment="Stretch" VerticalAlignment="Top" ItemsSource="{Binding TicketCollection}" Width="750" PreviewMouseDoubleClick="OpenReqList_PreviewMouseDoubleClick" IsSynchronizedWithCurrentItem="True">
        <ListView.View>
            <GridView >
                <GridView.Columns>
                    <GridViewColumn Width="100" Header="Ticket ID" DisplayMemberBinding="{Binding TicketID}"/>
                    <GridViewColumn Width="250" Header="Ticket Subject" DisplayMemberBinding="{Binding Path=TicketSubject}"/>
                    <GridViewColumn Width="190" Header="Ticket Send Time" DisplayMemberBinding="{Binding Path=TimeStamp}"/>
                    <GridViewColumn Width="190" Header="Ticket Status" DisplayMemberBinding="{Binding Path=TicketStatus}"/>
                </GridView.Columns>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>
public class cTicket
    {
        public string TicketID { get; set; }
        public string TicketStatus { get; set; }
        public string TicketSubject { get; set; }
        public string TicketDescription { get; set; }
        public string TicketTags { get; set; }
        public string TicketDiscussionID { get; set; }
        public string ResponseAdmin { get; set; }
        public string ResponseClient { get; set; }
        public string TimeStamp { get; set; }
    }

I am using this code to update my grid. It is not working. Grid is not updating. I cannot find any problem with the code. This is a Help Desk app. I am trying to update a closed ticket on the server with my grid on the client. HELP !

public class DAL_LOADTICKETS
{
    private static string URL ="http://helpdesk.hujelabs.com/user.php/"+Login.user_id+"/query/";
    public static void/*ObservableCollection<cTicket>*/ LoadOPENTICKETS()
    {
        // Execute the query using the LINQ to XML

        var tickets = from c in XElement.Load(URL).Elements("query") select c;
        foreach (var ticks in tickets)
        {
            cTicket lTicket = new cTicket
            {
                TicketID = ticks.Element("query_id").Value,
                TicketStatus = ticks.Element("status").Value,
                TicketSubject = ticks.Element("subject").Value,
                TicketDescription = ticks.Element("description").Value,
                TicketTags = ticks.Element("tag").Value,
                TimeStamp = ticks.Element("timestamp").Value,
            };
            if (ticks.Element("status").Value == "open")
            {
                if (!Window1.OpenTicketsList.Contains(lTicket))
                {
                    Window1.OpenTicketsList.Add(lTicket);
                }
            }

            else if (ticks.Element("status").Value == "closed")
            {
                if (Window1.OpenTicketsList.Contains(lTicket))
                {
                    Console.WriteLine("VISITED BUT NOT DELETED");

                    Window1.OpenTicketsList.Remove(lTicket);
                }
            }

        }

    }
<Grid Width="756" Background="White">
                    <ListView Name="OpenReqList" HorizontalAlignment="Stretch" VerticalAlignment="Top" ItemsSource="{Binding TicketCollection}" Width="750" PreviewMouseDoubleClick="OpenReqList_PreviewMouseDoubleClick" IsSynchronizedWithCurrentItem="True">
        <ListView.View>
            <GridView >
                <GridView.Columns>
                    <GridViewColumn Width="100" Header="Ticket ID" DisplayMemberBinding="{Binding TicketID}"/>
                    <GridViewColumn Width="250" Header="Ticket Subject" DisplayMemberBinding="{Binding Path=TicketSubject}"/>
                    <GridViewColumn Width="190" Header="Ticket Send Time" DisplayMemberBinding="{Binding Path=TimeStamp}"/>
                    <GridViewColumn Width="190" Header="Ticket Status" DisplayMemberBinding="{Binding Path=TicketStatus}"/>
                </GridView.Columns>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>
public class cTicket
    {
        public string TicketID { get; set; }
        public string TicketStatus { get; set; }
        public string TicketSubject { get; set; }
        public string TicketDescription { get; set; }
        public string TicketTags { get; set; }
        public string TicketDiscussionID { get; set; }
        public string ResponseAdmin { get; set; }
        public string ResponseClient { get; set; }
        public string TimeStamp { get; set; }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失退 2024-11-21 23:37:55

看起来您的代码正在构建一个新的 Ticket 并尝试从 ObservableCollection 中删除。尝试找到您收藏中已有的票证,然后将其删除。或者,您可能需要重写 Ticket 类上的 Equals,以便 ObservableCollection 知道您的新 Ticket 与旧 Ticket 相同。

It looks like your code is constructing a new Ticket and trying to remove it from the ObservableCollection. Try finding the Ticket that is already in your collection, then removing it. Alternatively, you may need to override Equals on your Ticket class so ObservableCollection knows that your new Ticket is equal to the old ticket.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文