gpt4 book ai didi

c# - 更改数据网格中特定行的颜色 C# windows ce compact framework

转载 作者:行者123 更新时间:2023-11-30 20:37:35 24 4
gpt4 key购买 nike

我正在使用 compact framework 2.0 在我的 windows ce handheld 上开发一个 c# 应用程序。我有一个像下面这样的网格

name        location  
----------------------
John US
Flex UK

我使用数据网格来形成网格。注意:DataGrid(new System.Windows.Forms.DataGrid()) 不是 DataGridView。网格上方有一个文本框。如果用户在文本框中输入 uk,我必须更改数据网格中第二行的颜色。我如何实现它??

 private System.Windows.Forms.DataGrid scnDataGrd = new System.Windows.Forms.DataGrid();

我添加了一个名为 status 的列。我想在那里显示一张图片。如果文本框中的文本匹配。

向表格添加列并根据 csv 填充值:

if (data.StartsWith("Coloumns"))
data = data.Substring(index + 1, data.Length - (index + 1));
data = data.Trim();
string[] values = data.Split(',');
// Add the index on the column on which data is stored in csv
List<int> csvIndex = new List<int>();
for (int i = 0; i < values.Length; i++)
{
values[i] = values[i].Trim();
if (values[i] != "Status")
csvIndex.Add(csvHeaders.IndexOf(values[i]));
}

rfidindex = (csvHeaders.IndexOf("RFID") == -1) ? csvHeaders.IndexOf("rfid") : csvHeaders.IndexOf("RFID");
//Image myImage = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("search.png"));
//ImageConverter imageConverter = new ImageConverter();
Image img = AssetGatherMobileQuickTraQ.Properties.Resources.search;
//Properties.Resources.my_image;
string csvdata = strRdr.ReadToEnd();
csvdata = csvdata.Replace('\r', ' ');
string[] tagDets = csvdata.Split(new char[] { '\n' });
csvItems = new Hashtable();
DataTable dataTable1 = (DataTable)scnDataGrd.DataSource;

for (int i = 0; i < tagDets.Length; i++)
{
string[] individTagDet = tagDets[i].Split(new char[] { ',' });

if (individTagDet.Length <= 1)
break;

csvItems.Add(individTagDet[rfidindex].Replace("\"", string.Empty).Trim(), individTagDet);
DataRow row = dataTable1.NewRow();
row.BeginEdit();
//System.Drawing.Image imgTest = System.Drawing.Image. FromFile("C:\\Test.jpg");
//System.Drawing.Image img = System.Drawing.Image.ReferenceEquals
//dataTable1.Columns
Bitmap image1 = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\search.png");


//scnDataGrd.Dara
row[0] = image1;
//DataGrid
for (int j = 0; j < 3; j++)
{
row[j+1] = individTagDet[csvIndex[j]].Replace("\"",string.Empty).Trim();
}
//scnDataGrd.TableStyles

csvRfidList.Add(individTagDet[rfidindex].Replace("\"", string.Empty).Trim());
missingTagList.Add(individTagDet[rfidindex].Replace("\"", string.Empty).Trim());

row.EndEdit();
dataTable1.Rows.Add(row);
scnDataGrd.DataSource = dataTable1;
}

如果文本经过处理,它会到达这里:

DataTable dataTable = (DataTable)scnDataGrd.DataSource;
int index1 = -1;
bool found = false;
DataGridTableStyle ts = new DataGridTableStyle();


foreach (DataRow dr in dataTable.Rows)
{
index1++;
if (dr[tableColIndex].ToString() == textValue)
{
scnDataGrd.Select(index1);
scnDataGrd.SelectionForeColor = Color.Red;
break;
}
else {

dr[0] = "Not Found";
}
}

在 Status Coloumn 中,它显示为 System.Data.Bitmap 而不是图像

最佳答案

你不能像那样提供图像,你必须为此制作自定义 ImageView ,但如果你想要 thisfrom 复选框,你可以这样实现:

if (data.StartsWith("Coloumns"))
data = data.Substring(index + 1, data.Length - (index + 1));
data = data.Trim();
string[] values = data.Split(',');
// Add the index on the column on which data is stored in csv
List<int> csvIndex = new List<int>();
for (int i = 0; i < values.Length; i++)
{
values[i] = values[i].Trim();
if (values[i] != "Status")
csvIndex.Add(csvHeaders.IndexOf(values[i]));
}

rfidindex = (csvHeaders.IndexOf("RFID") == -1) ? csvHeaders.IndexOf("rfid") : csvHeaders.IndexOf("RFID");
//Image myImage = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("search.png"));
//ImageConverter imageConverter = new ImageConverter();
Image img = AssetGatherMobileQuickTraQ.Properties.Resources.search;
//Properties.Resources.my_image;
string csvdata = strRdr.ReadToEnd();
csvdata = csvdata.Replace('\r', ' ');
string[] tagDets = csvdata.Split(new char[] { '\n' });
csvItems = new Hashtable();
DataTable dataTable1 = (DataTable)scnDataGrd.DataSource;

for (int i = 0; i < tagDets.Length; i++)
{
string[] individTagDet = tagDets[i].Split(new char[] { ',' });

if (individTagDet.Length <= 1)
break;

csvItems.Add(individTagDet[rfidindex].Replace("\"", string.Empty).Trim(), individTagDet);
DataRow row = dataTable1.NewRow();
row.BeginEdit();
//System.Drawing.Image imgTest = System.Drawing.Image. FromFile("C:\\Test.jpg");
//System.Drawing.Image img = System.Drawing.Image.ReferenceEquals
//dataTable1.Columns
Bitmap image1 = new System.Drawing.Bitmap(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\search.png");


//scnDataGrd.Dara
row[0] = image1;
//DataGrid
for (int j = 0; j < 3; j++)
{
row[j+1] = individTagDet[csvIndex[j]].Replace("\"",string.Empty).Trim();
}
//scnDataGrd.TableStyles

csvRfidList.Add(individTagDet[rfidindex].Replace("\"", string.Empty).Trim());
missingTagList.Add(individTagDet[rfidindex].Replace("\"", string.Empty).Trim());



row.EndEdit();
dataTable1.Rows.Add(row);

DataColumn cCurrent = new DataColumn("Current", typeof(bool));
dataTable1.Rows.Add(cCurrent);
scnDataGrd.DataSource = dataTable1;
}

在您的标准中,您可以像这样实现条件..

 DataTable dataTable = (DataTable)scnDataGrd.DataSource;
int index1 = -1;
bool found = false;
DataGridTableStyle ts = new DataGridTableStyle();


foreach (DataRow dr in dataTable.Rows)
{
index1++;
if (dr[tableColIndex].ToString() == textValue)
{
scnDataGrd.Select(index1);
scnDataGrd.SelectionForeColor = Color.Red;

dr["Current"] = true;
break;
}
else
{

dr[0] = "Not Found";
}
}

电流在

dr["Current"] = true;

是我们之前在倒数第三行实现的 DataColumn。在以前的代码上。

关于c# - 更改数据网格中特定行的颜色 C# windows ce compact framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35885123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com