C# mysql gridview koşullu renklendirme
12
●2.582
- 11-06-2014, 11:55:37altı kırmızı olan yere şunu yaz GridViewRow yada var yaz
yada kodunu bir yere upload et yolla bana - 11-06-2014, 11:56:25sana dedim kodların doğruysa çalışır diye.. Color olayı doğru ama senin kodların yanlış hocam..
o arkadaşın verdiği kod farklı bir eventte çalışıyor, onu o event haricinde çalıştırdığın için çalışmıyor. yani background a bu şekilde atama yapamazsın..
backcolor yerine DefaultCellStyle yazman gerekiyor. yani
row.Cells[1].DefaultCellStyle.BackColor = System.Drawing.Color.Red;
şeklinde yaparsan çalışması lazım.. - 11-06-2014, 12:54:51Bu şekilde de çalışmadı hocam kodum aşağıdaki gibi.
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { foreach (DataGridViewRow row in dataGridView1.Rows) { string RowType = row.Cells[1].Value.ToString(); if (RowType == "toptanci") { row.Cells[1].DefaultCellStyle.BackColor = System.Drawing.Color.Red; } else if (RowType == "perakendeci") { row.Cells[1].DefaultCellStyle.BackColor = System.Drawing.Color.Red; } } }
Formun tamamı ise su sekilde
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; using MySql.Data.MySqlClient; using MySql.Data; namespace Ys_Bilişim { public partial class Form2 : Form { public Form1 frm1; public Form3 frm3; public Form2() { InitializeComponent(); frm3 = new Form3(); frm3.frm2 = this; } MySqlConnection baglan = new MySqlConnection("Data Source=85.25.139.59;Database=efektasa_kredi;User ID=efektasa_kredi;Password=*;"); public Form1 Mdiparent { get; set; } DataTable tablo = new DataTable(); MySqlDataAdapter baglayici = new MySqlDataAdapter(); MySqlCommand komut = new MySqlCommand(); private void Form2_Load(object sender, EventArgs e) { string sqlsorgu = "Select * from kredi order by tarih DESC"; DataTable tablo = new DataTable(); komut.CommandText = sqlsorgu; komut.Connection = baglan; baglayici.SelectCommand = komut; baglan.Open(); baglayici.Fill(tablo); baglan.Close(); dataGridView1.DataSource = tablo; } public Form3 fmr3 { get; set; } private void button1_Click(object sender, EventArgs e) { frm3.ShowDialog(); } public Form2 frm2 { get; set; } private void button2_Click(object sender, EventArgs e) { baglan.Open(); string sqlsorgu = "Select * from kredi"; DataTable tablo = new DataTable(); MySqlDataAdapter baglayici = new MySqlDataAdapter(); MySqlCommand komut = new MySqlCommand(); komut.CommandText = sqlsorgu; komut.Connection = baglan; baglayici.SelectCommand = komut; baglayici.Fill(tablo); dataGridView1.DataSource = tablo; baglan.Close(); } private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { foreach (DataGridViewRow row in dataGridView1.Rows) { string RowType = row.Cells[1].Value.ToString(); if (RowType == "toptanci") { row.Cells[1].DefaultCellStyle.BackColor = System.Drawing.Color.Red; } else if (RowType == "perakendeci") { row.Cells[1].DefaultCellStyle.BackColor = System.Drawing.Color.Red; } } } private void textBox1_TextChanged(object sender, EventArgs e) { if (textBox1.Text.Trim() == "") { DataTable tablo = new DataTable(); tablo.Clear(); MySqlDataAdapter baglayici = new MySqlDataAdapter("Select * from kredi", baglan); baglayici.Fill(tablo); dataGridView1.DataSource = tablo; } else { DataTable tablo = new DataTable(); tablo.Clear(); MySqlDataAdapter baglayici = new MySqlDataAdapter("Select * from kredi where musteriismi Like '%"+textBox1.Text+"%'", baglan); baglayici.Fill(tablo); dataGridView1.DataSource = tablo; } } private void button3_Click(object sender, EventArgs e) { } } }
--R10.NET; Flood Engellendi -->-> Yeni yazılan mesaj 12:54:51 -->-> Daha önceki mesaj 12:17:57 --
Arkadaşlar ertan2002 arkadaşımız uzaktan bağlantı ile 10 saattir çözemediğim sorunu 5 dakika da çözdü kendisine minnetarım