简体   繁体   中英

Displaying command line output in a table

I'm running

wmic product get name,version

from the command line to get a list of installed programs and versions. I need to display this in a table in ac# windows form app, but I'm having difficulty with the dataGridView. Right now I'm just storing things in a List<string> but I don't know how to get that to display properly in the table. Any suggestions/help?

First, kinda stabbing in the dark Take a look at this tutorial

You really just need to put a datagridview on your form and then use this line

 List<string> t  = new list<string>();

 //Add your data

 dataGridView1.DataSource = t;

try and give more detail about what trouble you are having with your data grid if this did not answer your question

tjernigan, maybe this helps: the frist string on your list should be "Name Version". Note that every following version is aligned with the caption of the column.

So, on the first string, find the IndexOf "Version" and use this position to get a substring of the others.

Regards, Calil

Ended up just running wmic product get name and wmic product get version storing each one in a separate List and then doing:

for (int i = 0; i < names.Count; i++)
        {
            rows[0] = names.ElementAt(i).Trim();
            rows[1] = versions.ElementAt(i).Trim();
            programsGrid.Rows.Insert(i, rows);
        }

Thanks for all the suggestions.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM