I am populating a combobox with data from database. The data is being stored in a list. When I run the form, the combobox displays the right amount of GroupPlayers i.e. 2 but doesn't actually display the name of these groups, instead it displays the list (i think it's called, correct me if i am wrong) instance i.e. group.
Main form:
public void Groups() {
var smallGroups = new List<GroupsPlayers>();
//sql connections query etc etc is here
while(rd.Read())
{
var currentPlayer = new GroupsPlayers() {
GroupID = rd["GroupID"].ToString(),
GroupName = rd["GroupName"].ToString(),
};
smallGroups.Add(currentPlayer);
}
if(userResponse == DialogResult.Yes)
{
UpdatePlayer frmPlayers = new UpdatePlayer(smallGroups);
}
}
UpdatePlayer form
public class GroupsPlayers
{
public string GroupID { get; set; }
public string GroupName { get; set; }
}
List<GroupsPlayers> _GroupPlayers;
UpdatePlayer (List<GroupsPlayers> GroupPlayers)
{
_GroupPlayers = GroupPlayers;
}
private void BindCb()
{
cb.DataSource = _GroupPlayers;
cb.DisplayMember = "GroupName";
}
Also, when I use cb.ValueMemeber = "GroupID";
I get the error
Cannot bind to the new display member
Aucun commentaire:
Enregistrer un commentaire