1

我想在特定单元格中显示一个图标。

我正在使用此代码。我已经评论了我想在哪里显示图标:

string lastScripDate = this.GetLastScripDate(sFolderPath, pb);
string sQuery = "select * from database";
DataTable table = new DataTable();
table = this.Retrieve_Data(sQuery, "database");
pb.Maximum = table.Rows.Count;
pb.Value = 0;
double num = 0.0;
double num2 = 0.0;
double num3 = 0.0;
double num4 = 0.0;
if (table.Rows.Count > 0)
{
    for (int i = 0; i < table.Rows.Count; i++)
    {
        Application.DoEvents();
        dgv.Rows.Add();
        dgv.Rows[i].Cells["Sname"].Value = table.Rows[i]["Symbol"].ToString();
        dgv.Rows[i].Cells["clsprice"].Value = table.Rows[i]["SCRIP"].ToString();
        string str3 = table.Rows[i]["TradeType"].ToString();
        dgv.Rows[i].Cells["trd"].Value = str3;
        string str4 = str3;
        if (str4 != null)
        {
            if (!(str4 == "p"))
            {
                if (str4 == "q")
                {
                    goto Label_01DD;
                }
            }
            else
            {
               dgv.Rows[i].Cells["trd"].Style.ForeColor = Color.Green;///////I Want to Display Icon in this Cell(Up.Ico)
            }
        }
        goto Label_020B;
    Label_01DD:

        dgv.Rows[i].Cells["Trade"].Style.ForeColor = Color.Red;///////////////An Want to Display Icon in this Cell also(Down.Ico

    Label_020B:
    dgv.Rows[i].Cells["date"].Value = table.Rows[i]["TDate"].ToString();
        num = Convert.ToDouble(table.Rows[i]["CPrice"]);
        dgv.Rows[i].Cells["tp"].Value = string.Format("{0:0.00}", num);
        num2 = Convert.ToDouble(table.Rows[i]["Price"]);
        dgv.Rows[i].Cells["tp"].Value = string.Format("{0:0.00}", num2);
        num3 = Convert.ToDouble(table.Rows[i]["Loss"]);
        dgv.Rows[i].Cells["sl"].Value = string.Format("{0:0.00}", num3);
        try
        {
            num4 = Convert.ToDouble(table.Rows[i]["Ratio"]);
            dgv.Rows[i].Cells["Ratio"].Value = string.Format("{0:0.00}", num4);
        }
        catch
        { }
        pb.Value++;
    }
    if (pb.Value == pb.Maximum)
    {
        pb.Value = pb.Minimum;
    }
    return true;
}
return false;
4

2 回答 2

6

实现此目的的一种方法是添加DataGridViewImageColumn,然后将图标设置为该单元格。这是一个示例

        dataGridView1.Columns.Add(new DataGridViewImageColumn());
        dataGridView1.Rows.Add(2);

        DataGridViewImageCell cell = (DataGridViewImageCell)dataGridView1.Rows[0].Cells[0];

        Icon ic = new Icon("icon.ico");

        cell.Value = ic;
于 2012-06-14T04:26:00.047 回答
0

你可以通过使用DataGridViewImageColumn

于 2012-06-14T04:23:40.313 回答