Hi there,
I have a relational database, that I want to display in a DataGridView.
In that db, I have 2 Columns, some kind of a 'flag' (e.g. a processflag, -1 is not started yet, 0 is in progress, and 1 -process completed) - these flag I want do display in my DataGridView as an simple image.
My current solution is quite ugly.
Each Row, captured by a SQLDataReader is put through a Delegate into a method, which checks the row about the flag, and puts the row (incl. the image, selected of a imagelist) into object-List.
Afterwards, this object-List adds a new Row into the database.
This is my current SQLDataReader:
SqlCommand cmd = new SqlCommand(strQuery.ToString(), dbCls.sqlConnection);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
valuesForDgV = new List<string>();
valuesForDgV.Add(dr[0].ToString());
valuesForDgV.Add(dr[1].ToString());
valuesForDgV.Add(dr[2].ToString());
valuesForDgV.Add(dr[3].ToString());
valuesForDgV.Add(dr[4].ToString());
valuesForDgV.Add(dr[5].ToString());
valuesForDgV.Add(dr[6].ToString());
valuesForDgV.Add(dr[7].ToString());
valuesForDgV.Add(dr[8].ToString());
fillDgVDelegate dgvDelegate = new fillDgVDelegate(addData2DgV);
dgv_monthView.Invoke(dgvDelegate, valuesForDgV);
}
dr.Close();
private void addData2DgV(List<string> valueArray)
{
object flgProcess, flgArc = null;
if(valueArray[8] == "0" || valueArray[8] == short.MaxValue.ToString())
flgProcess = imageList1.Images[0];
else
flgProcess = imageList1.Images[1];
if (valueArray[7] == "0" || valueArray[7] == short.MaxValue.ToString())
flgArc = imageList1.Images[0];
else
flgArc = imageList1.Images[1];
dgv_monthView.Rows.Add(valueArray[0], betrag, valueArray[2], valueArray[3], valueArray[4], valueArray[5], flgWerbung, flgTermin, flgRechnung);
i don't know if it't an issue of the performance of my computer, but after, i guess 20 rows, the performance is going worse and worse.
So i've tried working with SQLDataAdapter, DataTable and BindingSource.
But I cannot use the Image in my DataGridView. the Column allows only Int-Values
What I need now, is a hint, a tip, may be a codesnippet, how i can solve this problem better.
I'm sorry, for my bad english and I hope you can understand my problem.
Thanks in advance,
Max
Edit:
I hope these screenshots will better show my problem:
this is what my database looks like:
Databasescreenshot
and this is, how I want to display the highlighted "flags" as an image, seen as the last three columns in my grid
DataGridView
So, I want the '0' Value to be an stop sign in the grid, and the 1-Value is the checked-sign.