thelonelyghost
thelonelyghost
CC#
Created by thelonelyghost on 1/1/2024 in #help
Need help with a telephone directory Windows Forms application
I am getting an exception when I try to click on a row to change the selected row in a DataGridView. The code is attached below: using System.Windows.Forms; namespace Lab_Prgm_8 { public partial class Form1 : Form { public class Entry { public string Name { get; set; } public string Contact { get; set; } } List<Entry> entries = new List<Entry>(); private void ClearTextBoxes() { textBoxName.Text = ""; textBoxContact.Text = ""; } public Form1() { InitializeComponent(); dataGridView1.DataSource = entries; } private void buttonAdd_Click(object sender, EventArgs e) { Entry newEntry = new Entry { Name = textBoxName.Text, Contact = textBoxContact.Text }; entries.Add(newEntry); dataGridView1.DataSource = null; // Refresh the data dataGridView1.DataSource = entries; ClearTextBoxes(); } private void buttonDelete_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { int selectedIndex = dataGridView1.SelectedRows[0].Index; entries.RemoveAt(selectedIndex); dataGridView1.DataSource = null; dataGridView1.DataSource = entries; ClearTextBoxes(); } else { MessageBox.Show("No entry selected for deletion!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
6 replies
CC#
Created by thelonelyghost on 12/27/2023 in #help
I'm VERY new to C#
I need help with a certain Lab Program of mine and I barely know anything in C#. Anyone willing to help please join the VC I am in so that I can show my code and my problem.
28 replies