C
C#2y ago
bernie2024

❔ ✅ Cant select an attribute of an object for display in a combobox or textbox

Hey Yall, working on a winforms grading application and having a wierd issue I cannot resolve. Instead of displaying a students name, or the assignments name, it just displays MidtermLib.Student, or MidtermLib.Assignment. I have tried to use the combobox methods DisplayMember and ValueMember to select the right column of the list based on the correct person, but it doesnt seem to be working. I have included a screenshot of the issue and the relevant code, any additional information needed I can provide. Thanks!
2 Replies
bernie2024
bernie2024OP2y ago
private void Form4_Load_1(object sender, EventArgs e) { // Populate ComboBox1 with all Student names students = dbManager.GetStudents(); comboBox1.DisplayMember = "FullName"; comboBox1.ValueMember = "StudentID"; comboBox1.DataSource = students; // Populate ComboBox2 with all Assignment names assignments = dbManager.GetAssignments(); comboBox2.DisplayMember = "AssignmentName"; comboBox2.ValueMember = "AssignmentID"; comboBox2.DataSource = assignments; // Update Earned Points and Total Points text boxes ComboBox_SelectedIndexChanged(this, EventArgs.Empty); } private void ComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedItem != null && comboBox2.SelectedItem != null) { CompletedAssignment assignment = (CompletedAssignment)comboBox2.SelectedItem; //Student student = (Student)comboBox1.SelectedItem; //textBox2.Text = assignment.TotalPoints.ToString(); textBox1.Text = assignment.EarnedPoints.ToString(); } } Methods in question ^^^ !close
Accord
Accord2y ago
Closed! Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server