Did you read comment from johannesnestler - 6 hrs ago? Debugging is important otherwise you have no chance in bigger projects.
Use this (Please note this is only a straight forward fast solution which runs according previous solutions (you forgot windows, and no null checking, and property name is and "DisplayName" and not "Disp
alyName"). I don't review each line.):
private void button1_Click_1(object sender, EventArgs e)
{
string DispalyName = null;
string RegistryKey = @"Software\Microsoft\Windows\Currentversion\UnInstall";
DataTable dt = new DataTable();
dt.Columns.Add("Software Name", typeof(string));
dt.Columns.Add("Software Version", typeof(string));
dt.Columns.Add("Software Publicher", typeof(string));
DataRow dr = null;
using (RegistryKey RegistryKey1 = Registry.LocalMachine.OpenSubKey(RegistryKey))
{
if (RegistryKey1 != null)
{
foreach (var varName in RegistryKey1.GetSubKeyNames())
{
using (RegistryKey RegisteyKey2 = RegistryKey1.OpenSubKey(varName))
{
if (RegisteyKey2 != null)
{
DispalyName = Convert.ToString(RegisteyKey2.GetValue("DisplayName"));
if (DispalyName.Equals(""))
{
continue;
}
else
{
dr = dt.NewRow();
dr[0] = (string)RegisteyKey2.GetValue("DisplayName");
if (RegisteyKey2.GetValue("DisplayVersion") == null)
dr[1] = "";
else
dr[1] = (string)RegisteyKey2.GetValue("DisplayVersion");
dr[2] = (string)RegisteyKey2.GetValue("Publisher");
dt.Rows.Add(dr);
}
}
}
}
}
}
GridSoftware.Columns.Clear();
GridSoftware.DataSource = dt;
}