Chair 17 Light Poster

Hi, if somebody can help me..
On main form, I have this set of alphabet letters and a datagridview. Each letter represents the first letter of each item in the datagrid. When a letter has items in the datagrid, it's underlined to show that it's clickable; no items=not clickable. When I click Edit to a row in the datagrid, another form comes up, and after I save the form, it should update the set of alphabet. So, if an item starts with letter A,A shows as clickable. But if I change it to B and save,letter B should now show as clickable, and A not.

Here are the relevant code snippets:

//on main form
public partial class FormMain : Form
    {
        
        Label[] lblalpha = null;

public FormMain()
        {
            InitializeComponent();
            lblalpha = new Label[26];

        }

        public FormMain(Label[] emplalpha,TabPage empltabpage)
        {
            InitializeComponent();
            lblalpha = emplalpha;
            tabPage2 = empltabpage;

        }

//function to create the alphabet
public void createAlphabet()
        {
            
            int x = 150;
            int y = 51;
            lblalpha = new Label[26];
            string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            char[] array = alphabet.ToCharArray();

            for (int i = 0; i < array.Length; i++)
            {
                
                char letter = array[i];
                lblalpha[i] = new Label();
                lblalpha[i].Text = letter.ToString();
                lblalpha[i].Location = new Point(x, y);
                lblalpha[i].Size = new Size(15, 13);

                Class1.readrecord("Select * from dbo.displayemplbylastname('" + lblalpha[i].Text + "')");
                if (Class1.dr.HasRows)
                {
                    lblalpha[i].ForeColor = Color.Blue;
                    lblalpha[i].Cursor = Cursors.Hand;
                    lblalpha[i].Font = new Font(lblalpha[i].Font, FontStyle.Underline);

                }
                Class1.con.Close();

                tabPage2.Controls.Add(lblalpha[i]);
                lblalpha[i].Click += new System.EventHandler(lblalpha_Click);
                x += 25;

            }

        }

//function to clear the alphabet
public void clearAlphabet()
        {

            string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            char[] array = alphabet.ToCharArray();

            for (int i = array.Length - 1; i >= 0; i--)
            {                
                tabPage2.Controls.Remove(lblalpha[i]);
                

            }

        } 

//when I click Edit to the datagridview row
private void dataGridViewempl_CellClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
if (dataGridViewempl.CurrentCell.RowIndex != -1)
            {
if (dataGridViewempl.CurrentCell.ColumnIndex == 5)
                {
                    FormEmployeeInfo formempl = new FormEmployeeInfo(tabPage2,lblalpha);
                    formempl.ShowDialog();

                }
            }

        }

}

//on the other form
public partial class FormEmployeeInfo : Form
    {
        
        private TabPage maintabpage;
        private Label[] mainalpha;
               
        public FormEmployeeInfo()
        {
            InitializeComponent();         
            maintabpage = new TabPage();
            mainalpha = new Label[26];  
            
            
        }

        
        public FormEmployeeInfo(TabPage thistabpage,Label[] thisalpha)
        {
            InitializeComponent();
            maintabpage = thistabpage;
            mainalpha = thisalpha;
            
}
           
//save changes
private void whensaved()
        {
            
            //to save record
            if (btnMale.Checked == true)
                saverecord("M");
            else if (btnfemale.Checked == true)
                saverecord("F");
                                
            //to refresh alphabet (clear previous set and create new set) 
            FormMain formmain = new FormMain(mainalpha,maintabpage); 
            formmain.clearAlphabet();           
            formmain.createAlphabet(); 
            

}

}

My problem is it refreshes the alphabet on the first edit, but not on subsequent edits. AND now, doesn't make the letters clickable. I tried to NOT pass back the tabpage to main form so letters will still be clickable, but it won't refresh the alphabet at all.

Pls help. My code's getting convoluted :=( Thanks much in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.