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
Solved

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

Posted on 2004-08-18
9
2,096 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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 …

808 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