How can i add to dataGridView1 a data to the last row/column?

Posted by user3681442 on Stack Overflow See other posts from Stack Overflow or by user3681442
Published on 2014-06-03T08:12:38Z Indexed on 2014/06/03 9:25 UTC
Read the original article Hit count: 138

Filed under:
|

In top of form1 i did:

private System.Timers.Timer _refreshTimer;
private int _thisProcess;

Then in the Form1 Load event:

_thisProcess = Process.GetCurrentProcess().Id;
InitializeRefreshTimer();
PopulateApplications();

Then the timer init method:

void InitializeRefreshTimer()
        {
            _refreshTimer = new System.Timers.Timer(5000);
            _refreshTimer.SynchronizingObject = this;
            _refreshTimer.Elapsed += new System.Timers.ElapsedEventHandler(TimerToUpdate_Elapsed);
            _refreshTimer.Start();
        }

Then the timer elapsed event:

void TimerToUpdate_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            PopulateApplications();
        }

In the end the Populate method:

void PopulateApplications()
        {
            dataGridView1.Rows.Clear();
            foreach (Process p in Process.GetProcesses("."))
            {
                if (p.Id != _thisProcess)
                {
                    try
                    {
                        if (p.MainWindowTitle.Length > 0)
                        {
                            String status = p.Responding ? "Running" : "Not Responding";
                            dataGridView1.Rows.Add( p.MainWindowTitle, status);
                        }
                    }
                    catch { }
                }
            }
        }

The variable status show in the column2 but let's say i want that status will be display for each process/app in column5 ? How can i move it ?

EDIT**

Tried this:

void PopulateApplications()
        {
            dataGridView1.Rows.Clear();
            foreach (Process p in Process.GetProcesses("."))
            {
                if (p.Id != _thisProcess)
                {
                    try
                    {
                        if (p.MainWindowTitle.Length > 0)
                        {
                            var icon = Icon.ExtractAssociatedIcon(p.MainModule.FileName);
                            Image ima = icon.ToBitmap();
                            img.Image = ima;
                            img.HeaderText = "Image";
                            img.Name = "img";
                            String status = p.Responding ? "Running" : "Not Responding";
                            dataGridView1.Rows.Add(img, p.MainWindowTitle, status);

                        }
                    }
                    catch { }
                }
            }
        }

I moved the variable img to the top of the form.

The problem is i see in each row this:

DataGridViewImageColumn { Name=img, Index=-1 }

And i don't see the icon it self. Why ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms