var p = new Person { Name = "张三", Address = "上海市乳山路", Sex = SexEnum.男 }
listView.Items.Add(p)
//Help class
public enum SexEnum { 男, 女 }
public class Person
{
public string Name { getset}
public string Address { getset}
public SexEnum Sex { getset}
}
提供两种方法:2.如果是根据类实现的数据绑定,只要在类中添加一个bool变量,默认值为true,绑定到checkbox就ok。这种情况下可以通过让类继承INotifyPropertyChanged 类的列表继承ObservableCollection实现。
附上一段代码,看不懂百度HI我。
using System
using System.Collections.Generic
using System.Linq
using System.Text
using System.ComponentModel
using System.Collections.ObjectModel
namespace AddrBook
{
public class People : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged
private void NotifyPropertyChanged(String propName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName))
}
}
private string name = string.Empty
public string Name
{
get { return name}
set
{
if (name == value)
{
return
}
else
{
name = value
NotifyPropertyChanged("Name")
}
}
}
private string phonenum = string.Empty
public string PhoneNum
{
get { return phonenum}
set
{
if (phonenum == value)
{
return
}
else
{
phonenum = value
NotifyPropertyChanged("PhoneNum")
}
}
}
private bool? ischecked = false
public bool? IsChecked
{
get { return ischecked}
set
{
if (ischecked == value)
{
return
}
else
{
ischecked = value
NotifyPropertyChanged("IsChecked")
}
}
}
}
public class Person : ObservableCollection<People>{ }
public class Group : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged
private void NotifyPropertyChanged(String propName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName))
}
}
private string groupname
public string GroupName
{
get { return groupname}
set
{
if (groupname == value)
{
return
}
else
{
groupname = value
NotifyPropertyChanged("GroupName")
}
}
}
private Person groupmember = new Person()
public Person GroupMember
{
get { return groupmember}
set
{
if (groupmember == value)
{
return
}
else
{
groupmember = value
NotifyPropertyChanged("GroupMember")
}
}
}
private int membercount = 0
public int MemberCount
{
get { return membercount}
set
{
if (membercount == value)
{
return
}
else
{
membercount = value
NotifyPropertyChanged("MemberCount")
}
}
}
private bool? ischecked = false
public bool? IsChecked
{
get { return ischecked}
set
{
if (ischecked == value)
{
return
}
else
{
ischecked = value
NotifyPropertyChanged("IsChecked")
NotifyMember(ischecked)
}
}
}
private void NotifyMember(bool? ischeck)
{
if (groupmember.Count >0)
{
foreach (People p in groupmember)
{
p.IsChecked = ischeck
}
}
}
}
public class GroupList : ObservableCollection<Group>{ }
}
还是给你整个文件吧
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)