1-) C# RMOS - gridView RowCellStyle refresh önleme çabaları
2-) SÜREKLİ SQL E GİTMEMEK İÇİN ÇARELER :)
ALGORİTMA ŞU ŞEKİLDEDİR :
DATATABLE'NİN KOPYASINI AL VE HER HÜCRE İÇİN RENGİNİ BELİRLE KOPYALADIĞIN DATATABLE BU RENKLERİ BELİRT. ÖRNEK 3.SATIR 2.SÜTÜN'ÜN RENGİ ARKAPLAN RENGİ SİYAH YAZI RENGİ BEYAZ OLSUN ŞU ŞEKİLDEDİR ROWS[3][2] = BLACK,WHİTE BUNU KOPYA OLAN DATATABLE YAZ VE SONRASINDA İSE CELLSTYLE EVENTİNDA HÜCRENİN SATIR VE SÜTÜNÜ BELLİ OLDUĞU İÇİN DİREK BU DATATABLE DEN ÇEK İF ELSE GEREK YOK YANİ. HER HÜCRENİN RENGİ BELLİ OLMAK ZORUNDADIR !!! RENGİ OLMASA BİLE OLMAYAN RENK BELLİ OLMAK ZORUNDADIR DEFAUL OLARAK WHİTE,BLACK DIR YANİ
kaynak kodlar : https://drive.google.com/open?id=1CQxShm1atoxnFtNS9e9L609ExSt-_ep2
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApp8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataBas();
}
public void dataBas()
{
DataTable dt = new DataTable();
dt.Columns.Add("maas", typeof(int));
dt.Columns.Add("ad", typeof(string));
dt.Columns.Add("ad1", typeof(string));
for (int i = 0; i < 500; i++)
{
dt.Rows.Add();
dt.Rows[i]["maas"] = 500 + i;
dt.Rows[i]["ad"] = "Ramazan Haber " + i;
dt.Rows[i]["ad1"] = "HH " + (i + 10);
}
gridControl1.DataSource = dt;
herCell_icinRenkBelirleme(dt);
}
DataTable copyDataTable; // HER CELL'İN RENGİ BELLİ OLMAK ZORUNDADIR !!!!
public void herCell_icinRenkBelirleme(DataTable dt)
{
copyDataTable = dt.Clone();
for (int i = 0; i < copyDataTable.Columns.Count; i++)
{
copyDataTable.Columns[i].DataType = typeof(string);
}
foreach (DataRow item in dt.Rows)
{
copyDataTable.Rows.Add();
}
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
if (dt.Columns[j].ColumnName == "maas")
{
int maas = Convert.ToInt32(dt.Rows[i][j]);
if (maas > 499 && maas < 550)
{
copyDataTable.Rows[i][j] = "Black,White"; // arkaplanrengi,yazırengi
}
else
{
copyDataTable.Rows[i][j] = "Yellow,Black"; // arkaplanrengi,yazırengi
}
}
else
{
copyDataTable.Rows[i][j] = "White,Black"; // default renk
}
}
}
}
private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
if (e.RowHandle >= 0)
{
GridView View = sender as GridView;
string columnName = e.Column.FieldName;
int visibleRowIndex = View.GetVisibleIndex(e.RowHandle);
//Console.WriteLine("Sütün =" + e.Column.FieldName + " - Satır = " + visibleRowIndex);
string arkaplanRengi = copyDataTable.Rows[visibleRowIndex][columnName].ToString().Split(',')[0].ToString().Trim();
string yaziRengi = copyDataTable.Rows[visibleRowIndex][columnName].ToString().Split(',')[1].ToString().Trim();
e.Appearance.BackColor = Color.FromName(arkaplanRengi);
e.Appearance.ForeColor = Color.FromName(yaziRengi);
}
}
}
}
3-) YUKARIDAKİ KODLARI KULLANIN YANİ AŞAĞIYA BAKMASANDA OLUR SADECE İNCELENMEK İÇİN YAZILDI
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApp8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dataBas();
}
int cellCount = 0;
public void dataBas()
{
cellCount = 0;
DataTable dt = new DataTable();
dt.Columns.Add("maas", typeof(int));
dt.Columns.Add("ad", typeof(string));
dt.Columns.Add("ad1", typeof(string));
for (int i = 0; i < 500; i++)
{
dt.Rows.Add();
dt.Rows[i]["maas"] = 500 + i;
dt.Rows[i]["ad"] = "Ramazan Haber " + i;
dt.Rows[i]["ad1"] = "HH " +( i+10);
}
gridControl1.DataSource = dt;
}
public int suandaEkrandaGozukebilecekMaxCellSayisi=45;
private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
/*
1- ÇALIŞTIĞI ANDA COUNT NE KADAR BAK BENIMKINDE 45 CUNKU 3(column)*15(satır) = 45
ekrandaki cell kadar donuyor 1 satırda 3 cell varsa 1*3 = 3 yapar
*/
if (cellCount > suandaEkrandaGozukebilecekMaxCellSayisi && goster==false)
{
/*
burasını sadece ilk gösterim için ekledim
*/
return;
}
cellCount++;
if (cellCount==gridView1.Columns.Count*3 ) // her imleç hareketi 3 satır ilerletir 3(satır)*3(column) = 9 yapar
{
cellCount = 0;
goster = false;
}
if (e.RowHandle >= 0)
{
GridView View = sender as GridView;
if (e.Column.FieldName == "maas" && (int)e.CellValue < 900)
{
e.Appearance.BackColor = Color.FromName("Black");
e.Appearance.ForeColor = Color.White;
}
}
}
public bool goster = false;
private void gridView1_TopRowChanged(object sender, EventArgs e)
{
/*
MOUSUN HER ORTA SCROLU İLE AŞAĞI İNMEK 3 SATIRA TEKAMÜL EDİYOR
*/
//cellCount = 0;
goster = true;
}
private void button1_Click(object sender, EventArgs e)
{
cellCount = 0;
}
}
}