判断表格指定列的内容是否已经存DataGridView

 

 

 

 

 

/*2021年10月3日 19:36:20
 * 判断表格指定列的内容是否已经存
 * 原理:循环查找表格指定列 ,如果这列的内容和查找的内容一样 则返回存在。
 *
 *参数
 * keyword:查找的关键字
 * findColumnText:要查找的列的文本 (列文本不区分大小写)
 */
public bool KeywordExists(string keyword, string findColumnText) {
    bool result = false;
    for (int i = 0; i < dgv1.Rows.Count; i++)
    {
        string s = dgv1.Rows[i].Cells[findColumnText].Value.ToString().Trim().ToLower();
        if (s == keyword)
        {
            result = true;
            break;
        }
    }
    return result;
}

 

使用

   button添加.Enabled = !KeywordExists(textBoxISBN.Text,"BooKISBN");

 

posted @ 2021-10-03 19:45  XE2011  阅读(221)  评论(0编辑  收藏  举报