Below is a code I’ve been working with for about two weeks now and thought I had it working till I put in the last information (Class MyClient) and now I’m getting a win32 error at the Process.Start(url);
Says the specified file cannot be found. I’ve tried setting it to “iexplorer.exe” to have it load IE for the URL, but no change.
public partial class Form1 : Form
{
List<MyClient> clients;
public Form1()
{
InitializeComponent();
clients = new List<MyClient>();
clients.Add(new MyClient { ClientName = "Client 1", UrlAddress = @"http://www.google.com" });
BindBigClientsList();
}
private void BindBigClientsList()
{
BigClientsList.DataSource = clients;
BigClientsList.DisplayMember = "ClientName";
BigClientsList.ValueMember = "UrlAddress";
}
private void BigClientsList_SelectedIndexChanged(object sender, EventArgs e)
{
MyClient c = BigClientsList.SelectedItem as MyClient;
if (c != null)
{
string url = c.ClientName;
Process.Start("iexplorer.exe",url);
}
}
}
class MyClient
{
public string ClientName { get; set; }
public string UrlAddress { get; set; }
}
}
You are using the
ClientNameas the URL, which is not correct……should be…
You shouldn’t specify
iexplorer.exeeither. By default, OS’s open URLs with the default web browser. Unless you really need your users using Internet Explorer, I suggest letting the system pick the browser for you.UPDATE
In respose to OP’s comment…
It depends on what you mean by “blank”. If you mean
null, no this is not possible. Usingnullas the first entry in your list will result in a NullReferenceException when you try to callc.UrlAddress. You might be able to use a place-holderMyClientinstance with dummy values…But then you would have to change your action method to something like this…