I'll start off with what i'm trying to do:
i want to search my data programmaticall y 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 autoscrollposit ion 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.co ntrols 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.
4 9903 Plater 7,872
Recognized Expert Expert
I always accomplished it by setting the selectedrows property to the one I wanted.
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: -
-
foreach (DataGridViewRow r in dataGrid.Rows)
-
{
-
if (((String)r.Cells[col].Value).Equals(text))
-
{
-
r.Selected = true;
-
//rest of the code
-
}
-
}
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.Select edRows 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
Plater 7,872
Recognized Expert Expert
Well I take that back, I double-checked and I use the CurrentCell property -
//dgvParts is my dataGridView
-
//setting currentcell would push the focus to that cell, but I have "select whole row" enabled so it selects the row
-
private void SelectPartIDMatching(string PartID)
-
{
-
int myidx = -1;
-
for (int i = 0; i < dgvParts.Rows.Count; i++)
-
{
-
if (dgvParts["PartID", i].Value.ToString() == PartID)
-
{
-
myidx = i;
-
break;
-
}
-
}
-
if (myidx != -1)
-
{
-
dgvParts.CurrentCell = dgvParts.Rows[myidx].Cells[0];
-
}
-
}
-
Well I take that back, I double-checked and I use the CurrentCell property -
//dgvParts is my dataGridView
-
//setting currentcell would push the focus to that cell, but I have "select whole row" enabled so it selects the row
-
private void SelectPartIDMatching(string PartID)
-
{
-
int myidx = -1;
-
for (int i = 0; i < dgvParts.Rows.Count; i++)
-
{
-
if (dgvParts["PartID", i].Value.ToString() == PartID)
-
{
-
myidx = i;
-
break;
-
}
-
}
-
if (myidx != -1)
-
{
-
dgvParts.CurrentCell = dgvParts.Rows[myidx].Cells[0];
-
}
-
}
-
That works just fine! Thanks a lot now i can finally stop wrestling with this issue
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 that integer to set
the 'Y' coordinate for the div.
Can this be done? If so, how?
If not, any other suggestions?
|
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, the vertical scrollbar on the left
side will be moved down a little bit but if the page is loaded with
Internet explorer, the scrollbar remains at the top of the scroll area.
|
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. How could I associate the
two controls to work as if they where only one?
Thank you for your help
Carmen
|
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 left,
I want to display 0% on the form.
- if the horizontal scrollbar is smack in the middle,
I want to display 50% on the form.
- if the horizontal scrollbar is 2/3rd along the X-axis,
|
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 scrollbar with a Touch screen
Regards
| |
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 displaying in DIV tag with scroll bar.
Problem : when page is refreshed scrollbar position is going to change everytime. So, if user scroll up the divtag and seeing his data then page is refreshed and scrollbar position is again going to change.
I...
|
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., the listbox must scroll down as if I
clicked the bottom arrow of the scrollbar.
Is it possible?
Or is something impossible in c#? :)
Thanks.
|
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 subclassed my OCX to add a vertical scrollbar.
The scrollbar works fine.
Problem:
Some of the embedded controls are only visible when another control is
|
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 inconsistent in the detection of a vertical scrollbar. This
involves situations when less than the client area is needed to hold
the small amount of data. The inconsistency is when adjusting the
panel size within or just below the bottom row....
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |