Forum guidelines
AuthorQuestion
Moving a linklabel up or down
Posted on: 03 Jan 2013
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



AuthorReply
Re: Moving a linklabel up or down
Posted on: 04 Jan 2013  
Before attempting your problem, I want to clarify some points:
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" ?

Hemant Srivastava | MVP (C# Corner) | http://hemant-srivastava.blogspot.com/
Re: Moving a linklabel up or down
Posted on: 04 Jan 2013  
recentlyvistdsites.zip Listbox, dont worry about the save project as recentlyvistedsites. I have attached what I have done so far, but am totally confused on how to click the link and make it move up while the other two move down.

Re: Moving a linklabel up or down
Posted on: 05 Jan 2013  
Hi Justin,

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.

Hemant Srivastava | MVP (C# Corner) | http://hemant-srivastava.blogspot.com/
Re: Moving a linklabel up or down
Posted on: 05 Jan 2013  
recentlyvistdsites 2.zip Im still not understanding, here is my code, I uploaded the correct file. Can you help me with this one

Re: Moving a linklabel up or down
Posted on: 05 Jan 2013  
updownmover.rar This time I am able to open your solution, but I noticed you put your 3 linklabels on the top of the listview and so those linklabels are not basically items of the listview. However in the form load  , you are adding "URL STRING" (not linklabel) but that formLoad is not attached to actual Form.. it is just a loosely placed private method. Ok, I am attaching my program whose code I pasted yesterday. In that, items are moving up-down but item are strings not Linklabels. Meanwhile I will try to find some way ... how to play with actual LinkLabel controls instead of URL String.

Hemant Srivastava | MVP (C# Corner) | http://hemant-srivastava.blogspot.com/
Re: Moving a linklabel up or down
Posted on: 05 Jan 2013  
Yes your code is good, but the listview can be removed from my code. Plus the project requires the user to click on the linkLabel and it goes to the website and it moves to the top of the list after clicking it. Its just like going to recently viewed websites and putting the most recent one at the top.

Re: Moving a linklabel up or down
Posted on: 07 Jan 2013  
updownmover.zip Hey Justin,

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...!!

Hemant Srivastava | MVP (C# Corner) | http://hemant-srivastava.blogspot.com/
Re: Moving a linklabel up or down
Posted on: 09 Jan 2013  
Did yuo check my previous solution? Hope it should work for you. Let me know if you see any issue.
Hemant Srivastava | MVP (C# Corner) | http://hemant-srivastava.blogspot.com/
aa ss
  • 0
  • 0
Re: Moving a linklabel up or down
Posted on: 11 Jan 2013  
http://www.jordan11playoffshoes.com/
http://www.jordan11playoffshoes.com/
http://www.jordan11playoffshoes.com/

http://www.air9coolgrey.com/
http://www.air9coolgrey.com/
http://www.air9coolgrey.com/

http://www.cheapfoampositespink.com
http://www.cheapfoampositespink.com
http://www.cheapfoampositespink.com

http://www.retro4thunder.com/
http://www.retro4thunder.com/
http://www.retro4thunder.com/


http://www.allfoampositegalaxy.com/
http://www.allfoampositegalaxy.com/
http://www.allfoampositegalaxy.com/
http://www.allfoampositegalaxy.com/

http://www.monclervestsjacket.com/
http://www.monclervestsjacket.com/moncler-coats-men-cheap-30.html
http://www.monclervestsjacket.com/moncler-coats-women-cheap-31.html
http://www.monclervestsjacket.com/moncler-jackets-men-cheap-32.html
http://www.monclervestsjacket.com/moncler-jackets-women-cheap-33.html

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.