Results 1 to 11 of 11

Thread: [2005] DataGridView Cell XY Location

  1. #1
    New Member
    Join Date
    Oct 08
    Posts
    4

    Smile [2005] DataGridView Cell XY Location

    I have a datagridview on my form and I want to know the location of a cell in the datagridview. For example, I want to know the xy location of the cell in the second row of the second column. I used the following code:

    dg_Schedule.Rows(6).Cells(1).ContentBounds.Y


    The above code doesn't work because the Y point gives the wrong value and doesn't change when I scroll. How can I resolve this problem? I want to know the location even if there's no scrolling.

    If I want to place a listview on top of a cell in the datagridview, how would I make it move along with the datagridview while the user is scrolling it?


    Thanks.



  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,785

    Re: [2005] DataGridView Cell XY Location

    Again, read the documentation. You're already using the ContentBounds property. The documentation for that property provides the answer to your question:
    The returned rectangle reports client coordinates, in pixels.

    This property calls the GetContentBounds method to get its value. For the base DataGridViewCell type, this value is Empty.

    To get the bounding rectangle of the cell rather than the cell contents, use the DataGridView.GetCellDisplayRectangle method.
    The answer was there the whole time but you just didn't look. You won't be able to answer every question by reading the documentation and forums like this are great when you've looked but can't find, or can't understand, what you need. The documentation should ALWAYS be the fist place you look though. You'll often learn things you weren't even looking for too. I speak from my own personal experience.

  3. #3
    New Member
    Join Date
    Jun 12
    Posts
    1

    Re: [2005] DataGridView Cell XY Location

    Quote Originally Posted by jmcilhinney View Post
    Again, read the documentation. You're already using the ContentBounds property. The documentation for that property provides the answer to your question:The answer was there the whole time but you just didn't look. You won't be able to answer every question by reading the documentation and forums like this are great when you've looked but can't find, or can't understand, what you need. The documentation should ALWAYS be the fist place you look though. You'll often learn things you weren't even looking for too. I speak from my own personal experience.
    I created an account on this forum just so I can comment on this most snarky remark... what a pompous @ss you are. Consulting Microsoft's VB.Net documentation is a painful experience as it is not informative at all and is so contrived. Not to mention the See Also section is useless for the most part. You can tell MS documentation was written by C++ and Assembly programmers who live in their own little worlds.

    That's folks like the OP consult the Internet and forums like this in the hope of getting a quick and informed response.

    So get off your high horse and work on your people skills.

    Good day to you sir!!

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,785

    Re: [2005] DataGridView Cell XY Location

    Quote Originally Posted by NorthernDG View Post
    I created an account on this forum just so I can comment on this most snarky remark... what a pompous @ss you are. Consulting Microsoft's VB.Net documentation is a painful experience as it is not informative at all and is so contrived. Not to mention the See Also section is useless for the most part. You can tell MS documentation was written by C++ and Assembly programmers who live in their own little worlds.

    That's folks like the OP consult the Internet and forums like this in the hope of getting a quick and informed response.

    So get off your high horse and work on your people skills.

    Good day to you sir!!
    So, just in case the documentation is too hard to understand, it's better to not even bother reading it. Is that what you're saying? As I said in this very thread, forums like this are great when you have looked for the answer and can't find it or don't understand it when you do. In this case, finding the answer using the documentation would have taken about 30 seconds. How is it not better to take 30 seconds to find the answer for yourself than to wait over 2 hours for someone else to tell you the same thing? By encouraging people to be lazy you are not helping them. You are just making it take much longer for them to get information that is easy to find.

  5. #5
    New Member
    Join Date
    Aug 12
    Posts
    2

    Re: [2005] DataGridView Cell XY Location

    I agree 100% that guy was being a total @ss. MS documentation is certainly not always the best place to look.

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 06
    Location
    Providence, RI - USA
    Posts
    9,167

    Re: [2005] DataGridView Cell XY Location

    If you're here long enough, you will agree that JMC is one of the best members in this forum (just look at his reputation points). When I first joined this forum, I myself sometimes didn't like the way JMC help others by advising them to go read the documentation first, but I took his advice anyway and it has proven to be really helpful. I also find that most of the stuff I'm looking for is right there in the documentation most of the times. If you're working on a project and get stuck on something, posting a question to this or any other forum could take many hours (if not days) for you to get the right answer while it could take possibly just a few minutes to check on the documentation.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  7. #7
    Lively Member
    Join Date
    Apr 10
    Posts
    67

    Re: [2005] DataGridView Cell XY Location

    I haven't been here long, but JMC has already helped me with quite a few things. You have to realize that you need to have a certain amount of tolerance for those who have mastery over a certain area. Instead of just asking to be spoon fed the information, you should try to at least explain WHY you cant solve the problem, or name a few things you've tried. At the very least you need to explain that you've tried Googling and cannot find exactly what you're looking for. If someone who knows more sees that you are totally off track, you will be helped. That's what makes these forums so valuable.

  8. #8
    New Member
    Join Date
    Aug 12
    Posts
    2

    Re: [2005] DataGridView Cell XY Location

    So your saying its OK for someone to be that way because they are smart or have been here a while? I'm sorry but no, that is BS. There is no reason to do that kind of thing. Seems like a good example of how the internet has made people think it is OK to be a jerk just because you're not talking to someone face to face. Does he do that kind of thing at work too? I bet he doesn't, but for some reason it's OK to do on the net.

  9. #9
    Lively Member
    Join Date
    Apr 10
    Posts
    67

    Re: [2005] DataGridView Cell XY Location

    No, I'm just saying that you cant always expect to get expert advice without proving that you've made the effort to solve the problem yourself.

  10. #10
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,785

    Re: [2005] DataGridView Cell XY Location

    Quote Originally Posted by ejthayer View Post
    I agree 100% that guy was being a total @ss. MS documentation is certainly not always the best place to look.
    I did not say, nor have I ever said, that the documentation will always answer every question. What I am saying is that the documentation contains a lot of information and will answer many, if not most questions, especially when they relate to a specific type or member. The fact that the documentation MIGHT not provide the answer to your question is not justification for DEFINITELY not even looking for it. It's not like I don't know what I'm talking about. When I was a beginner in .NET I was on my own. I had no job and I was at home with my computer. MSDN was always my first port of call when I had a problem and I found the answer there more often than not. Not only that, I found lots of information that I wasn't looking for that helped me at some point in the future. You'll notice that I joined this forum in May 2005. That's about 2 years after I started learning .NET, so I spent 2 years using MSDN as my primary source of information before making a post to a forum. After I joined here, I answered many questions posted by others on subjects I had no previous experience with (primarily the Windows Forms DataGrid control) simply by reading the appropriate documentation. If I could read the documentation and answer their question, why couldn't they read the documentation for themselves? Noone can tell me that you can't answer your own questions using MSDN because I've done it myself, so I know for a fact that it's not true.

  11. #11
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,785

    Re: [2005] DataGridView Cell XY Location

    Quote Originally Posted by ejthayer View Post
    So your saying its OK for someone to be that way because they are smart or have been here a while? I'm sorry but no, that is BS. There is no reason to do that kind of thing. Seems like a good example of how the internet has made people think it is OK to be a jerk just because you're not talking to someone face to face. Does he do that kind of thing at work too? I bet he doesn't, but for some reason it's OK to do on the net.
    You could make that bet but you'd lose your money. I have an expectation that people will make what effort they can to help themselves before expecting others to take the time and make the effort to help them. It's no more than I expect from myself and it's no more than I have done since starting programming. One thing that people like you probably don't even consider is the fact that I've seen this all before. You might ask one or two questions or see someone else post one or two questions and you see me say "read the documentation" and you assume that I just like shooting people down. I've seen lots of people post difficult questions and I've answered many of them. I've also seen lots of people post elementary questions that they could have answered for themselves in minutes, if not seconds, had they just read the relevant documentation. In those cases I have pointed that out. Many of those people have done so and thanked me for it. Some others have abused me for it. I don't even need the thanks but, if some people can do it, what does that say about those who won't even try?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •