user3681442
user3681442

Reputation: 297

After adding icons of each process to dataGridView1 the last one is red x why it happens ? I checked for null but nothing is null

In form1 I have this method that I've called through a timer, in the designer I changed the first column type to: DataGridViewImageColumn

private void test()
   {

    foreach (Process p in Process.GetProcesses())
                {
                    if (p.MainWindowTitle.Length > 1)
                    {
                        var icon = Icon.ExtractAssociatedIcon(p.MainModule.FileName);
                        Image ima = icon.ToBitmap();
                        String status = p.Responding ? "Running" : "Not Responding";
                        dataGridView1.Rows.Add(ima,p.MainWindowTitle, status);
                    }
   }
                }

Now what I'm getting is this:

enter image description here

In first iteration I have seen all the icons but in the end I see red x . I tried to check if the variable ima is null but it is not, then checked that variable p is null or p.MainWindowTitle is null but nothing is null. What could be the cause of this red x ?

Second thing(not connected to the red x issue): in the first time first iteration I have seen 9 icons(not including the red x) in the second timer iteration it's adding another icon so there are 10. Why it is not adding all the 10 icons for the first time ?

Upvotes: 0

Views: 652

Answers (2)

Alejandro del Río
Alejandro del Río

Reputation: 4046

Try with datagridview property AllowUserToAddRows = false This way it wont show the last empty row.

Upvotes: 1

fishmong3r
fishmong3r

Reputation: 1434

Just remove it.

var row = dataGridView1.Rows[dataGridview.Rows.Count-1];
dataGridView1.Rows.Remove(row);

Regarding the 2nd issue. Is that 10th process running at the first time as well? What process is that?

Upvotes: 1

Related Questions