我試圖將DataGridView綁定到MembershipUserCollection,但網格拒絕顯示任何用戶,即使數據庫中有記錄。將WinForms DataGridView綁定到MembershipUserCollection
根據我在互聯網上的研究,我做了以下內容:
MembershipUserCollection x = Membership.GetAllUsers();
gvUsers.DataSource = x;
感謝你的幫助。
我試圖將DataGridView綁定到MembershipUserCollection,但網格拒絕顯示任何用戶,即使數據庫中有記錄。將WinForms DataGridView綁定到MembershipUserCollection
根據我在互聯網上的研究,我做了以下內容:
MembershipUserCollection x = Membership.GetAllUsers();
gvUsers.DataSource = x;
感謝你的幫助。
的問題是,您綁定到需要的對象來實現這些接口
IList
IListSource
IBindingList
IBindingView
之一而MembershipUserCollection只實現ICollection
。
一種解決方案是創建一個實現這些接口之一的包裝器/適配器。
這可能工作,不能測試atm。
var collection = Membership.GetAllUsers();
var bindingList = new BindingList<MemberShipUser>();
// If it's only meant for display
bindingList.AllowNew = false;
bindingList.AllowRemove = false;
bindingList.AllowEdit = false;
foreach (MemberShipUser member in collection)
{
bindingList.Add(member);
}
也許這很明顯,但我不得不從MemberShipUser到MembershipUser的小調整。
設置bindingList作爲我的數據網格的數據源,它工作的很棒!
'x.Count!= 0'? – InBetween 2011-06-15 12:28:20
是的,我檢查了x.count = 3 – AbZy 2011-06-15 12:29:16