如何从列表中获取更改的项目地址? [英] How can I get changed item address from the list ?

查看:80
本文介绍了如何从列表中获取更改的项目地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有List< class>当用户更改UI时,如何从列表中获取更改的项目地址?谢谢〜



  class 用户界面
{
public RadioButton rdo;
// 其他......
}

列表< uis> ListUI = new 列表< uis>();
private void creat()
{
for int i = 0 ; i < 20 ; i ++)
{
UIs UI = new UIs();
UI.rdo.CheckedChanged + = changedCheck;
ListUI.Add( new UIs());
}
}
私有 void changedCheck( object sender,EventArgs e)
{
RadioButton rdo =(RadioButton)sender;
}





我的尝试:



如果用户改变了rdo



我试图使用这个事件,但所有的rdo看起来都是一样的..... />


如何从列表中获取更改项目的地址

解决方案

问题是你有一个RadioButton( rdo)和一个List< uis>对于每个UI实例 - 并且您没有将值设置为 rdo ,直到该按钮的CheckChangedEvent为止。但是事件永远不会发生,因为你试图将它添加到新实例的 rdo 中,该实例不包含任何内容并将抛出NullReferenceException。

除此之外,您的RadioButtons永远不会向用户显示,因此他无法更改它们!



这假设在某些你打电话给你的 creat 方法。



我认为你需要坐下来仔细考虑一下正是你想要做的事情,因为那段代码非常困惑,看起来它是用GAP模式抛出的一样 *

我无法解决你的问题正在努力,但不是这样,我敢肯定!



* GAP:猜猜并祈祷

I have List<class> when UI changed by the user, How can I get changed item address from the list? thanks~

class UIs
{
    public RadioButton rdo;
    // others......
}

List<uis> ListUI = new List<uis>();
private void creat()
{
    for (int i = 0; i < 20; i++)
    {
        UIs UI = new UIs();
        UI.rdo.CheckedChanged += changedCheck;
        ListUI.Add(new UIs());
    }
}
private void changedCheck(object sender, EventArgs e)
{
    RadioButton rdo = (RadioButton)sender;
}



What I have tried:

If rdo was changed by UI

I was tried to use the event, but all rdo was looked the same.....

How can I get changed item's address from the list

解决方案

The problem is that you have one RadioButton (rdo) and one List<uis> for each instance of a UIs - and you don't set a value to rdo until the CheckChangedEvent for that button. But the event will never happen, because you try to add it to the rdo for the new instance, which doesn't contain anything and will throw a NullReferenceException.
Added to that, your RadioButtons are never shown to the user, so he can't change them!

That's assuming that at some point you call your creat method.

I think you need to sit down and think a bit more carefully about exactly what you are trying to do, because that code is very confused, and looks like it's been thrown together using the GAP Pattern*
I can't work out what you are trying to do, but that isn't it, I'm sure!

* GAP : "Guess And Pray"


这篇关于如何从列表中获取更改的项目地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆