Solved

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

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

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
Comment Utility
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
 
LVL 2

Expert Comment

by:mahanatti
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:kvnsdr
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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 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…

743 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

18 Experts available now in Live!

Get 1:1 Help Now