简体   繁体   English

在表中显示命令行输出

[英]Displaying command line output in a table

I'm running 我在跑

wmic product get name,version wmic产品得到名称,版本

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. 我需要在ac #windows窗体应用程序的表中显示它,但是我在使用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. 现在我只是将事物存储在List<string>但我不知道如何在表中正确显示。 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 你真的只需要在表单上放一个datagridview然后使用这一行

 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". tjernigan,也许这会有所帮助:列表中的frist字符串应为“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. 因此,在第一个字符串上,找到IndexOf“Version”并使用此位置获取其他字符串的子字符串。

Regards, Calil 此致,Calil

Ended up just running wmic product get name and wmic product get version storing each one in a separate List and then doing: 结束只运行wmic product get namewmic product get version将每个存储在一个单独的列表中然后执行:

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. 感谢所有的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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