dimanche 14 juin 2020

Add if statement if value already exists in range in c#

I want to add in a check to see if a value being inputted from a gridview to a range is already in the range. If the value is already in the range I do not want it added and I would like a popup to say the value already exists in this range. I have the code that adds in the value, but need to add in the check so no duplicate values are added into the range. Is there a code, if statement etc, to check if the value added to the "Doc_Glossary" range is already a value in that range?

       if (dataGridViewGloss.Rows[i-9] != null)
        {
                Range line = (Range)Doc_GlossaryWorksheet.Rows[i];
                line.Insert();
                m_xlApp.ActiveWorkbook.Worksheets["Doc_Glossary"].Cells[i, 5].Value = dataGridViewGloss.Rows[i - 9].Cells[0].Value;
                m_xlApp.ActiveWorkbook.Worksheets["Doc_Glossary"].Cells[i, 6].Value = dataGridViewGloss.Rows[i - 9].Cells[1].Value;

Aucun commentaire:

Enregistrer un commentaire