473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C# DataGridView & Scrollbar position setting problem

I'll start off with what i'm trying to do:

i want to search my data programmatically and then jump to the row in the datagrid.
My data will almost allways go out of the datagrids bounds so if the found result is not on screen at the time i want to 'scroll' to the result.

sounds simple enough right?


Some things i've tried to get the datagrid to do what i want:

-setting the autoscrollposition property, i've tried setting it after finding the result and tried setting it in the paint loop (which was an advice found while looking for an awnser on the net)

neither had any visible effect, the property changed but didn't show in the controll after invalidation & painting. so i discarded this avenue as the incorrect appoach


-Getting the VScrollBar from the datagridview.controls list and then setting its value directly to the position on which i want it to be.

now this actually had some effect: the scrollbars handle appeared on the correct position, but the datagrid did not scroll along. now if i touch/drag the handle of the scrollbar then it does update the position and i'm near my result (depending on howfar i dragged the handle)
so the problem here seems to be that the datagrid doesn't seem to pick up the change until i actually use a physical mouseinput on the scrollbar

i'm currently trying to invoke the scrollbars mouseclick/drag whatever but so far i havn't made any process in that area yet.


Now my question is:
-does anybody have any idea of how to get the datagrid to pick up the change, or does anybody have another method of setting the scrolloffset which actually shows.

basically i'm running into walls when i'm looking through the internet/msdn and i'm running out of ideas so any help would be welcome.
Jul 31 '07 #1
4 9866
Plater
7,872 Expert 4TB
I always accomplished it by setting the selectedrows property to the one I wanted.
Jul 31 '07 #2
I always accomplished it by setting the selectedrows property to the one I wanted.
that was 1 of the things that came to mind, when i was kicking against this problem heres how i do my selection atm:

Expand|Select|Wrap|Line Numbers
  1.  
  2.             foreach (DataGridViewRow r in dataGrid.Rows)
  3.             {
  4.                 if (((String)r.Cells[col].Value).Equals(text))
  5.                 {
  6.                     r.Selected = true;
  7. //rest of the code
  8. }
  9. }
which highlights the selection but doesn't seem to scrolldown to the first highlighted entry

after reading your post i tried to simply set the datagrid.SelectedRows list but thats read only, so would u mind posting a quick example of how you do it?

btw i forgot to mention i'm using .Net 2.0
Jul 31 '07 #3
Plater
7,872 Expert 4TB
Well I take that back, I double-checked and I use the CurrentCell property
Expand|Select|Wrap|Line Numbers
  1. //dgvParts is my dataGridView
  2. //setting currentcell would push the focus to that cell, but I have "select whole row" enabled so it selects the row
  3. private void SelectPartIDMatching(string PartID)
  4.         {
  5.             int myidx = -1;
  6.             for (int i = 0; i < dgvParts.Rows.Count; i++)
  7.             {
  8.                 if (dgvParts["PartID", i].Value.ToString() == PartID)
  9.                 {
  10.                     myidx = i;
  11.                     break;
  12.                 }
  13.             }
  14.             if (myidx != -1)
  15.             {
  16.                 dgvParts.CurrentCell = dgvParts.Rows[myidx].Cells[0];
  17.             }
  18.         }
  19.  
Jul 31 '07 #4
Well I take that back, I double-checked and I use the CurrentCell property
Expand|Select|Wrap|Line Numbers
  1. //dgvParts is my dataGridView
  2. //setting currentcell would push the focus to that cell, but I have "select whole row" enabled so it selects the row
  3. private void SelectPartIDMatching(string PartID)
  4.         {
  5.             int myidx = -1;
  6.             for (int i = 0; i < dgvParts.Rows.Count; i++)
  7.             {
  8.                 if (dgvParts["PartID", i].Value.ToString() == PartID)
  9.                 {
  10.                     myidx = i;
  11.                     break;
  12.                 }
  13.             }
  14.             if (myidx != -1)
  15.             {
  16.                 dgvParts.CurrentCell = dgvParts.Rows[myidx].Cells[0];
  17.             }
  18.         }
  19.  
That works just fine! Thanks a lot now i can finally stop wrestling with this issue
Jul 31 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

24
by: Jeff Johnson | last post by:
Hi All, I'm setting a <div> on a page on a lengthy page with a great deal of text. I want the div to land where the user can see it. I need to capture the vertical scrollbar position and use...
1
by: alvinpoon | last post by:
Hello, I have a problem setting the scrollbar position of a div region on a webpage which is posted at http://www.geocities.com/virtuosity999/Logon.htm If the page is loaded with Netscape,...
2
by: carmen | last post by:
I need to have in a form a listbox with a big scrollbar (I'm working for a touchscreen). As the scrollbar that the listbox has is small, I put a listbox withou scroll and a scrollbar independent....
6
by: Colin McGuire | last post by:
Hello experts, this is a repost but I have been (much) more clear. I want to know the position of the horizontal scrollbar in a textbox as a percentage - if the horizontal scrollbar is hard...
1
by: steve | last post by:
Hi All Is there anyway to change the width of datagridview controls vertical scrollbar I have an Application where the datagridview fills most of the screen and it is hard to grab the...
0
by: ranabhavin2 | last post by:
Hi , I have made chat application in asp.net using atlas. It is database chat. So, every 1 minutes page is going to refresh and fetch data from database. All the data of chatting I m...
1
by: orofiamma | last post by:
It may appear odd, but I need to control the vertical scrollbar position of a listbox by buttons. So I'll have a "Scroll up" button and a "Scroll down" button. When I click "Scroll down", i.e.,...
0
by: =?Utf-8?B?Q2hyaXN0aWFuIEhhdmVs?= | last post by:
Hi, I have the following problem in VB, but I think some C++ freaks have more in deep understanding: I have an OCX which contains an picture box which works as a container for controls. I...
1
by: Tom | last post by:
First, I posted a similar request for help in another group and now don't find the posting. Problem with my newsreader perhaps ... but apologies if this appears as a cross posting. My code is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.