Solved

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

Posted on 2004-08-18
9
2,091 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wordcount challenge 11 121
egit plugin on eclipse 8 62
Beginner to Unreal Engine 4 5 79
Is doing tutor.com teaching in my situation advisable? 2 82
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now