Solved

Windows Forms (Not ASP) DataGrid or ListView Hyperlink ???

Posted on 2004-08-18
9
2,098 Views
Last Modified: 2010-07-27
Does anyone know if its possible to hyperlink a datagrid or a ListView column in windows forms, not ASP???
I've found many articles on ASP, however I cannot find anything on Windows forms........

I would like to click on an IP in datacolumn that opens a web page (whois) at arin.net like:

http://ws.arin.net/cgi-bin/whois.pl?queryinput=120.210.120.100
0
Comment
Question by:kvnsdr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 11838222
Well You can use LinkLabel control on one column of the DataGrid. Search for "HOW TO: Add a ComboBox Control to a Windows Form DataGrid Control" in MSDN and add a LinkLabel instead of ComboBox.

However if you just want that a Web Page is openend when user clicks on one of the cells of the grid just trap the MouseUp event get the value of the CurrentCell and call a function to open a browser and redirect to the URL.

0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 11838347

Try this code in Listview click event handler

 System.Diagnostics.Process.Start( "http://ws.arin.net/cgi-bin/whois.pl?queryinput= " &  ListView1.SelectedItems(0).Text)

regards
Prakash
0
 
LVL 2

Expert Comment

by:mahanatti
ID: 11838403
Hi,

Get the cell that is clicked(current cell) using Hittest or Datagrid's click event, take the corresponding text out of the cell and then open the required URL using the Process class in System.Diagnostics namespace.

-Maha.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:mahanatti
ID: 11838416
Follow this link to add a pushbutton to the datagrid. If required you may use a linkbutton instead of pushbutton and directly open the URL in the click event of the pushbutton/linkbutton.

http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q888q

-Maha.
0
 
LVL 1

Author Comment

by:kvnsdr
ID: 11841570
I receive the following error message when compiling in VS.NET C# and 'SelectedItems' is underlined...........


'System.Windows.Forms.ListView.SelectedItems' denotes a 'property' where a 'method' was expected
0
 
LVL 1

Author Comment

by:kvnsdr
ID: 11846375
Does anyone know if its possible to hyperlink a datagrid or a ListView column in windows forms, not ASP???
I've found many articles on ASP, however I cannot find anything on Windows forms........

I would like to click on an IP in datacolumn that opens a web page (whois) at arin.net like:

http://ws.arin.net/cgi-bin/whois.pl?queryinput=120.210.120.100

I tried this code in the Listview click event handler:

 System.Diagnostics.Process.Start( "http://ws.arin.net/cgi-bin/whois.pl?queryinput= " &  ListView1.SelectedItems(0).Text)

However, I received the following error message when compiling in VS.NET C# and 'SelectedItems' is underlined...........

'System.Windows.Forms.ListView.SelectedItems' denotes a 'property' where a 'method' was expected

I'm increasing the points too...........

Q. I'm new here and not sure how to handle the "points". Seems that the higher the points, the quicker the answer. Just curious if there is money or some other reward for the most points............

0
 
LVL 1

Author Comment

by:kvnsdr
ID: 11846941
I had to correct the (0) to [0] to eliminate a compiling error. So this code enables any clicked IP in my listView1 to open the following URL and view the IP DNS info. However, I still don't have a viewable 'underline' in the listView1 column of IP's...... Still working on that one... Something to do with styles...........

private void listView1_ClickToUrl(object sender, System.EventArgs e)
 {
   System.Diagnostics.Process.Start( "http://ws.arin.net/cgi-bin/whois.pl?queryinput= " +  listView1.SelectedItems[0].Text);
  }


                                     
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 11857975
Hi
Try this code :

declartions
---------------
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint="SendMessageW", SetLastError=true)]
            private static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, long lParam);

            public const int LVM_SETEXTENDEDLISTVIEWSTYLE  = (0x1000 + 54);
            public const int LVS_EX_ONECLICKACTIVATE  = 0x40;
            public const int LVM_GETEXTENDEDLISTVIEWSTYLE=(0x1000 + 55);
--------------------

Call thi sfunction on form load
---------------------------
ChangeItems(ref listView1,0,Color.Blue);
SendMessage(listView1.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_ONECLICKACTIVATE,LVS_EX_ONECLICKACTIVATE | styles);
---------------------------------

private void ChangeItems(ref ListView lv,int ColumnIndex,Color color)
{
foreach(ListViewItem lvI in lv.Items)
{
lvI.SubItems[ColumnIndex].Font = new Font("Times New Roman",10,System.Drawing.FontStyle.Underline);
lvI.SubItems[ColumnIndex].ForeColor=color;
}

}

regards
prakash
0
 
LVL 10

Accepted Solution

by:
prakash_prk earned 500 total points
ID: 11879708

Set this properties for list view

listView1.Activation = System.Windows.Forms.ItemActivation.OneClick;
listView1.Cursor = System.Windows.Forms.Cursors.Hand;
listView1.FullRowSelect = true;
listView1.MultiSelect = false;

Use the following code

private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
            {
                  System.Diagnostics.Process.Start(listView1.SelectedItems[0].Text);
            
            }
            
regards
prakash
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question