Solved

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

Posted on 2004-08-18
9
2,103 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

752 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