DataGridView Kontrolünde Kayıt Arama

Merhaba arkadaşlar bu makalemizde DataGridView kontrolünde ki sutunlarda kayıt arayacağız.  Bulunan kayıtın satır arka plan rengini değiştireceğiz.

Screenshot

Şekil 1
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
            this.customersTableAdapter.Fill(this.northwindDataSet.Customers);

        }

        private void btnFind_Click(object sender, EventArgs e)
        {

            string ara = txtFind.Text.Trim();
    
            int i = -1;
     
     
      foreach (DataGridViewRow row in dataGridView1.Rows)
      {
        
              foreach (DataGridViewCell cell in row.Cells)
              {
                  if (cell.Value != null)
                  {
                      if (cell.Value.ToString() == ara)
                      {
                          //kayit bulundugunda arka plan rengini degistiriyoruz.
                          cell.Style.BackColor = Color.Yellow;
                          i = 0;
                          break;
                      }

                  }
              }
         
    }
      if (i == -1)
      {
        MessageBox.Show("Kayıt bulunamadı");
      }

        }
    }
}

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN

About Bahadır Şahin

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.

0 comments:

Öne Çıkan Yayın

GridView da Seçili Satırı DetailsView da Göstermek

Merhaba arkadaşlar bu makalemizde GridView nesnesi ile birlikte DetailsView nesanesini birlikte kullanacağız. GridView da seçili satırın de...