I need help with the last part of this, How do I make a link move to the top of the list after I click it???????????????????????? Please help me somebody
Create a Form with a list of three LinkLabels that link to any three Web sites you choose. When a user clicks a linkLabel, link to that site. When a user mouse hoovers over a LinkLabel, display a brief message that explains the sites purpose. After a user clicks a link, move it to the top of the list and move the other two links down, making sure to retain the correct explanation with each link. Save the project as RecentlyVistedSites
Loading
aa ssPosted Jan 11, 2013, 2:12 AM
Hemant SrivastavaPosted Jan 9, 2013, 11:02 AM
Hemant SrivastavaPosted Jan 7, 2013, 4:43 PM
Since we can't add Controls on ListView so I drop the idea of adding LinkLabel Control in ListView. I added them in TableLayoutPanel controls. Then I played little bit and got the way what you need. Check the attached program...!!
Justin CrowderPosted Jan 5, 2013, 8:02 PM
Hemant SrivastavaPosted Jan 5, 2013, 7:45 PM
Justin CrowderPosted Jan 5, 2013, 1:25 PM
Hemant SrivastavaPosted Jan 5, 2013, 1:28 AM
Your attached project could not be opened. It looks, it was just a solution not any source file..
Anyway, to move item (link in this case) in Listview, you need to basically bubble up the selected item unless its index position is reached at top. Suppose you have some links in a list view as:
private void Form1_Load(object sender, EventArgs e)
{
listView1.Items.Add("http:\\www.yahoo.com");
listView1.Items.Add("http:\\www.google.com");
listView1.Items.Add("http:\\www.gmail.com");
listView1.Items.Add("http:\\www.hotmail.com");
listView1.Items.Add("http:\\www.youtube.com");
listView1.Items.Add("http:\\www.wright.edu");
}
Now you select an item on a listview and click a button for selection (...you don't need basically a seperate button for link clicking, but here for the sake of simplicity I made it seperate. You may put the same logic on ListViewItemSelectionChanged event handler)
private void btnLinkSelect_Click(object sender, EventArgs e)
{
while (listView1.SelectedItems[0].Index != 0)
{
MoveUp();
}
}
private void MoveUp()
{
int indexs = (listView1.SelectedItems[0].Index) - 1;
if (indexs > -1)
{
//Bubbling up item by swaping values
string current = listView1.SelectedItems[0].Text;
string aboveOne = listView1.Items[indexs].Text;
listView1.SelectedItems[0].Text = aboveOne;
listView1.Items[indexs].Text = current;
ListViewItem nextItem = listView1.Items[indexs];
nextItem.Selected = true;
listView1.Items[indexs + 1].Selected = false;
listView1.Focus();
listView1.Refresh();
}
else
{
ListViewItem nextItem = listView1.SelectedItems[0];
nextItem.Selected = true;
listView1.Focus();
}
}
On running this program, we see following screen before pressing LinkSelect button:
and after clicking LinkSelect button, items are bubbled up to the top and you would see like:
Hope it might be helpful for you! if it works for you, you may make this answer as an accepted.
Justin CrowderPosted Jan 4, 2013, 1:37 PM
Hemant SrivastavaPosted Jan 4, 2013, 11:09 AM
1. Do you want to put your LinkLabels in a ListBox or dataGrdi or ListView?
2. Could you eloberate more on : "Save the project as RecentlyVistedSites" ?