I try to develop ac# application(gathering products by their barcodes) to windows ce handheld device with compact framework 3.5
I have a datagrid and datagrid is bind with a datatable by sql. There are 4 columns in my datagrid, 3rd column represents the quantity of the products needs to be collected, and last column comes with the default value 0(quantity collected). Whenever user enters a product code, quantity of the product increases 1 by 1.
I want to make background color of the row blue when user enters corresponding product code(to show which product is being collected)
and also I want to make background color green if user collects the needed products.
I tried coloring row by selected index but it does not work. When selection gone , colours are gone.
Here is a picture of screen when needed quantity of product was collected.
Here is when I want to see the processed row.
Below is my code of the keypress event of the textbox(entering of product code)
private void txtUrunkod_KeyPress(object sender, KeyPressEventArgs e)
{
foreach (System.Data.DataColumn col in dt.Columns) col.ReadOnly = false;
if (e.KeyChar == (char)Keys.Enter)
{
islemkod = txtUrunkod.Text;
islemkod.Trim();
if (islemkod.Contains('/'))
{
serikodbol = islemkod.Split('/');
urunKodum = serikodbol[0];
DataRow row = dt.Select("urunkodu='" + urunKodum + "'").FirstOrDefault();
int guncelle = Convert.ToInt32(row[3]);
guncelle++;
row[3] = guncelle;
}
else if (islemkod.Length == 8)
{
SqlCommand cmd = new SqlCommand("exec MY_TOPUK_BILGI_GETIR '" + islemkod + "'", conStr);
conStr.Open();
SqlDataReader dr = cmd.ExecuteReader();
uk = new DataTable();
uk.Load(dr);
conStr.Close();
//toplamaGrid.Select(0);
foreach (DataRow row2 in uk.Rows)
{
urunKodum = row2[0].ToString();
}
DataRow row = dt.Select("urunkodu='" + urunKodum + "'").FirstOrDefault();
int guncelle = Convert.ToInt32(row[3]);
guncelle++;
row[3] = guncelle;
int index = -1;
bool found = false;
foreach (DataRow datr in dt.Rows)
{
index++;
string d = datr["urunkodu"].ToString();
if (datr[0].ToString() == urunKodum)
{
found = true;
break;
}
}
if (found && !row[2].Equals(row[3]))
{
toplamaGrid.Select(index);
toplamaGrid.SelectionBackColor = Color.Blue;
}
else if (row[2].Equals(row[3]))
{
toplamaGrid.Select(index);
toplamaGrid.SelectionBackColor = Color.Green;
//toplamaGrid.UnSelect(index);
}
}
else if (islemkod.Length == 7 && islemkod[0] == 'P')
{
}
else//islemkod.Length != 8 && !islemkod.Contains('/')
{//
urunKodum = txtUrunkod.Text;
txtUrunkod.Visible = false;
lblurunkod.Visible = false;
txtifAdres.Visible = true;
lbladressor.Visible = true;
txtifAdres.Focus();
}
updated = true;
txtUrunkod.Text = "";
sonindex = 0;
}
}
I couldnt find many info about this. Any help will be important. Thanks for any help!
First of all I experienced the same problem. Make use of DataGridFormatCellEventArgs for coloring the solution.
explained here Add the DataGrid file to your code in the link. ( DataGridFormatCellEventArgs.cs and FormattableTextBoxColumn.cs ) These files contain the Paint class that was used to do the coloring.
I hope I could help. If you experience difficulties, I can give an example from my own code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.