Forum

Datagridview hücre ...
 
Bildirimler
Hepsini Temizle

Datagridview hücre kontrolü

3 Yazılar
2 Üyeler
0 Likes
402 Görüntüleme
(@yildirimbakar)
Gönderiler: 97
Estimable Member
Konu başlatıcı
 

Merhaba Arkadaşlar;

Datagridview'e combobox'tan seçime göre veriler geliyor. Datagridview'de boş olan Değer1,Değer2,Değer3 diye kolonlarım var. Comboboxtan gelen değerlere göre Değer1'e veri girdiğimde aşağıdaki gibi Asgari değerden büyükse durum combobox'i kabul yapıyor ve rengini beyaz yapıyor. Değilse durum combobox'i boş bırakıyor ve o hücrenin arka planını kırmızı yapıyor. Ben bu işlemin aynısını Değer2 ve Değer3 için nasıl yapabilirim acaba? Yeni bir for döngüsü oluşturunca Değer1'i girdikten sonra Değer 2'yi girince hata veriyor.

Teşekkür ederim.  

for (int i = 0; i < dataGridView.Rows.Count - 1; i++)
{
if (dataGridView.Rows[i].Cells["Deger1"].Value != null)
{
if ((Convert.ToSingle(dataGridView.Rows[i].Cells["Deger1"].Value) >= Convert.ToSingle(dataGridView.Rows[i].Cells["AsgariDeger"].Value)))
{
dataGridView.Rows[i].Cells["Deger1"].Style.BackColor = Color.White;
DataGridViewComboBoxCell comboBoxCell = (dataGridView.Rows[i].Cells["Durum"] as DataGridViewComboBoxCell);
comboBoxCell.Value = "Kabul";
}
else
{
dataGridView.Rows[i].Cells["Deger1"].Style.BackColor = Color.Red;
DataGridViewComboBoxCell bos = (dataGridView.Rows[i].Cells["Durum"] as DataGridViewComboBoxCell);
bos.Value = string.Empty;
}
}
else
{
dataGridView.Rows[i].Cells["Deger1"].Style.BackColor = Color.White;
}

 
Gönderildi : 31/05/2023 16:50

Hakan Uzuner
(@hakanuzuner)
Gönderiler: 32993
Illustrious Member Yönetici
 

Merhaba, bu kodu dener misin?

 

for (int i = 0; i < dataGridView.Rows.Count - 1; i++)
{
DataGridViewRow row = dataGridView.Rows[i];

// Değer1 için kontrol
if (row.Cells["Deger1"].Value != null)
{
float deger1 = Convert.ToSingle(row.Cells["Deger1"].Value);
float asgariDeger = Convert.ToSingle(row.Cells["AsgariDeger"].Value);

if (deger1 >= asgariDeger)
{
row.Cells["Deger1"].Style.BackColor = Color.White;
DataGridViewComboBoxCell comboBoxCell = (row.Cells["Durum"] as DataGridViewComboBoxCell);
comboBoxCell.Value = "Kabul";
}
else
{
row.Cells["Deger1"].Style.BackColor = Color.Red;
DataGridViewComboBoxCell comboBoxCell = (row.Cells["Durum"] as DataGridViewComboBoxCell);
comboBoxCell.Value = string.Empty;
}
}
else
{
row.Cells["Deger1"].Style.BackColor = Color.White;
}

// Değer2 için kontrol
if (row.Cells["Deger2"].Value != null)
{
float deger2 = Convert.ToSingle(row.Cells["Deger2"].Value);
float asgariDeger2 = Convert.ToSingle(row.Cells["AsgariDeger2"].Value);

if (deger2 >= asgariDeger2)
{
row.Cells["Deger2"].Style.BackColor = Color.White;
// İlgili combobox hücresini işleme tabi tutabilirsiniz.
}
else
{
row.Cells["Deger2"].Style.BackColor = Color.Red;
// İlgili combobox hücresini işleme tabi tutabilirsiniz.
}
}
else
{
row.Cells["Deger2"].Style.BackColor = Color.White;
}

// Değer3 için kontrol
if (row.Cells["Deger3"].Value != null)
{
float deger3 = Convert.ToSingle(row.Cells["Deger3"].Value);
float asgariDeger3 = Convert.ToSingle(row.Cells["AsgariDeger3"].Value);

if (deger3 >= asgariDeger3)
{
row.Cells["Deger3"].Style.BackColor = Color.White;
// İlgili combobox hücresini işleme tabi tutabilirsiniz.
}
else
{
row.Cells["Deger3"].Style.BackColor = Color.Red;
// İlgili combobox hücresini işleme tabi tutabilirsiniz.
}
}
else
{
row.Cells["Deger3"].Style.BackColor = Color.White;
}
}

 

Danışman - ITSTACK Bilgi Sistemleri
****************************************************************
Probleminiz Çözüldüğünde Sonucu Burada Paylaşırsanız.
Sizde Aynı Problemi Yaşayanlar İçin Yardım Etmiş Olursunuz.
Eğer sorununuz çözüldü ise lütfen "çözüldü" olarak işaretlerseniz diğer üyeler için çok büyük kolaylık sağlayacaktır.
*****************************************************************

 
Gönderildi : 31/05/2023 18:01

(@yildirimbakar)
Gönderiler: 97
Estimable Member
Konu başlatıcı
 

@hakanuzuner 

Hakan bey;

Cevabınız için çok teşekkür ederim. İstediğim gibi oldu. Fakat şöyle bir sıkıntım var. Aşağıdaki gibi yazdığımda girdiğim iki değerde kabulse hata vermiyor. Girmiş olduğum bir değer asgari ve azami değerin dışındaysa aşağıdaki gibi hata veriyor.

 

image
image

 

for (int i = 0; i < dataGridView.Rows.Count - 1; i++)
{
DataGridViewRow row = dataGridView.Rows[i];

// Değer1 için kontrol
if (row.Cells["Deger1"].Value != null)
{
float deger1 = Convert.ToSingle(row.Cells["Deger1"].Value);
float asgariDeger = Convert.ToSingle(row.Cells["AsgariDeger"].Value);
float azamiDeger = Convert.ToSingle(row.Cells["AzamiDeger"].Value);

if (deger1 >= asgariDeger && deger1<=azamiDeger)
{
row.Cells["Deger1"].Style.BackColor = Color.White;
DataGridViewComboBoxCell comboBoxCell = (row.Cells["Durum"] as DataGridViewComboBoxCell);
comboBoxCell.Value = "Kabul";
}
else
{
row.Cells["Deger1"].Style.BackColor = Color.Red;
DataGridViewComboBoxCell bos = (dataGridView.Rows[i].Cells["Durum"] as DataGridViewComboBoxCell);
bos.Value = string.Empty;
}
}
else
{
row.Cells["Deger1"].Style.BackColor = Color.White;
}

// Değer2 için kontrol
if (row.Cells["Deger2"].Value != null)
{
float deger2 = Convert.ToSingle(row.Cells["Deger2"].Value);
float asgariDeger2 = Convert.ToSingle(row.Cells["AsgariDeger"].Value);
float azamiDeger2 = Convert.ToSingle(row.Cells["AzamiDeger"].Value);

if (deger2 >= asgariDeger2 && deger2 <= azamiDeger2)
{
row.Cells["Deger2"].Style.BackColor = Color.White;
DataGridViewComboBoxCell comboBoxCell = (row.Cells["Durum"] as DataGridViewComboBoxCell);
comboBoxCell.Value = "Kabul";
}
else
{
row.Cells["Deger2"].Style.BackColor = Color.Red;
DataGridViewComboBoxCell bos = (dataGridView.Rows[i].Cells["Durum"] as DataGridViewComboBoxCell);
bos.Value = string.Empty;
}
}
else
{
row.Cells["Deger2"].Style.BackColor = Color.White;
}

Bu ileti 11 ay önce Yıldırım bakar tarafından düzenlendi
 
Gönderildi : 01/06/2023 17:57

Paylaş: