How can I use a Hyperlink inside a Listbox?

Asked

Viewed 58 times

1

I want to make a HyperLink for each result that will appear within the ListBox.

    private void listBox_SelectionMode(object sender, EventArgs e)
    {
        LogisticaServiceContractClient Logistica = new LogisticaServiceContractClient();

        var Autos = Logistica.RetornoRomaneioPostagemPorImagem(2, retornoList.ToArray());

        if (Autos != null)
        {
            Autos.ToList().ForEach(delegate(RetornoRomaneioPostagemDataContract naoRetornado)
            {
                clog.ArquivoLog("Autos nao retornados:", String.Format("Numero auto: {0}, Tipo notificacao: {1}", naoRetornado.Numero_Auto, naoRetornado.Tipo_Notificacao), "arq.txt");
                Autos_Invalidos.Items.Add(naoRetornado.Numero_Auto);
            });

            MessageBox.Show("Nao foi possivel efetiar o retorno");
        }
        else
        {
            MessageBox.Show("Autos retornados");
        }
    }

1 answer

0

A simple and effective example of how to treat items like Hyperlinks:

private ListBox _listBox1;

public void Initialize()
{
    MyObject myObject = new MyObject();
    myObject.DisplayName = "Google";
    myObject.URL = "http://www.google.com";

    _listBox1.Items.Add(myObject);
    _listBox1.DisplayMember = "DisplayName";
    _listBox1.SelectedIndexChanged += _ListBox1_SelectedIndexChanged;
}

private void _listBox1_SelectedIndexChanged(object pSender, EventArgs pArgs)
{
    MyObject myObject = (MyObject)_listBox1.SelectedItem;
    Process.Start(myObject.URL);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.