So I have a vanilla DataGridView in a WinForms solution.
As you tab through the cells in the DataGrid eventually you reach a point where the selected cell is only half in view. In order to view it you must scroll over.
Well this is obviously something that I want to handle automatically so the question is....
How do I enable my DataGridView to scroll automatically as the user tabs.
I searched for a scroll bar index value or position value but couldn't seem to find anything.
DataGrid
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.aspx
I think you are looking for something like FirstDisplayedCell to control your scroll.
dataGridView1.FirstDisplayedCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0];
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.firstdisplayedscrollingrowindex.aspx
Related
I have created an array of ListBox in which I have populated with some data from a text file. I want to change between each Listbox when the user scrolls either left or right so each one can be displayed. How would I go about doing this? I have populated my user interface with the first List-box Listbox(0).
I don't fully understand your question, but if you are trying to put the scrollbar to the left side of the listbox, you can set the RightToLeft property to true.
If you want to move from one ListBox to another the better control to use is a Slider then a ScrollBar
I want to make programmatically scrolling in GridView and prevent user from doing it by himself. I tried to do something like in code below:
GridView.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Hidden);
GridView.ScrollIntoView(GridView.Items[10]);
GridView.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Disabled);
Unfortunately after disabling vertical scroll bar display of GridView back to first row.
EDIT: After all there was really simple solution. Instead of changing values of VerticalScrollBarVisibilityProperty I disabled VerticalScrollModeProperty.
I'm not getting your requirement clearly but it'd be better to use ScrollViewer on top of your gridview and scroll it programmatically using:
ScrollViewer.ScrollToHorizontalOffset(Offset Value);
Or using PropertyMetaData. You can also enable/disable the scrollviewer based on your requirements.
To be clear I'm talking about Grid - not GridView or DataGrid or anything like that.
All I found online was about GridView and such.
I want to be able to select items with a mouse click or drag from a Grid.
What I have is a table filled with text implemented through a Grid. I want to be able to select "cells" in the Grid.
The reason I don't use DataGrid is because I couldn't find a way to set a cell's span.
Thank you,
Dolev.
I had nearly the same approach some month ago: Dynamic ui with rows and columns
Maybe this will help you.
In the end I used Selector.IsSelected attached property.
Selector Class
I modified the MouseDown, MouseUp, MouseMove event to record a rectangle created when dragging the mouse while the left button is held. Then I checked which cells are within that rectangle.
As a double check to see that the cell is really selected I used Selector.SetIsSelected and Selector.GetIsSelected.
I am currently working on a project that displays user data in a grid, each user has a total and when clicked expands out to show the sub items that make up that total and they can be expanded again to show even more details.
I currently achieve this by using a DataGridView with its data bound to a DataTable, I hide the sub items for each user in the "RowsAdded" event and then just show/hide them as the main user lines/sub lines are clicked.
The Main problem with this is the scroll bar jumps a lot when data is changed and I require it to only move when the user wants it to.
I also have a requirement that no line must ever be covered and the parent lines should show totals of the values in the child (I can do this part manually the more important part is that its not a grouping like with a outlook style list).
My question is: Is there a better way to have expanding entries in a table format? And if hiding and un-hiding is the only way then any idea how to fix the scrolling problem?
I have tried hiding and showing lines as I have already said and I have also tried hiding and showing another Control (in this case another DataGridView) the problem with this approach is that it covers the other rows as I have yet to find a suable way to pad out a space for the control to be in.
You can use the following code to eliminate the scrolling animation.
dataGridView1.ScrollBars = ScrollBars.None;
// Do your show/hide on your datagridview rows
dataGridView1.ScrollBars = ScrollBars.Both;
In the End there was no satisfactory way to do this with winforms so I was forced to swap to WPF and I had everything running in about 2 hours.
My end solution was to use a DataGrid with rowdetails that contain a DataGrid.
I've a datagrid in WPF, It has lots of records hence having a VerticalScrollBar, when i do some activity like delete in some where at bottom of the screen and after this activity set the first index of the row, First row has been selected but scrollbar remains at the same position(bottom). I want it to be at the top or wherever the selected row is.
Thanks
After you perform the delete, you can use a combination of UpdateLayout and ScrollIntoView DataGrid methods. Ensure you call the UpdateLayout method before calling the ScrollIntoView method.