I am trying to use Visual C# to make an editable row/column matrix. Essentially what I want to do is this:
The Row and Col values will be editable and i would like for the amount of cells to resize inside its bounds. That is, if i change the rows to this:
The bounds should stay the same.
What sort of Container should I begin using? I have tried a panel control with coloured labels but I can't think of how to resize them?
Just drag the DataGridView control from your toolbox onto your form:
I've used the following code before to distribute the column widths evenly:
base.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
An AutoSizeRowsMode property also exists.
Related
I've create a c# winforms form,
It has a bunch of labels positioned and a flowlayoutpanel.
on certain occasions i set one of the labels and the flowlayoutpanel to visible =false.
As a result i want all labels beneath them to be pushed up - at the moment there is a gap where they were.
Also, I'd like the flowlayoutpanel to grow and shrink depending on the number of items it has.
at the moment it is just the size i set it to be in the designer.
please can you help with these 2 issues.
Thanks
If I got you correctly, I would suggest using a TableLayoutPane with two rows. The top row will contain a docked panel with all the controls that may be hidden. The bottom row will contain a docked panel with all the rest.
Set the top row's SizeType to AutoSize and the bottom row's to 100%.
When you want to hide the controls, set the top panel's Visible property to false. Now, because the top row is AutoSized it will shrink to nothing, causing the bottom row to "jump" up.
The TableLayoutPanel does the pushing. Maybe you can use that if there is no better answer in next time.
First problem:
You may use some simple panels to divide your form, give them the dock.fill property. when you'll hide a panel programmatically, the other panels will fill the empty space left.
Second problem:
You have to set the Autosize property to true.
How to give TableLayoutPanel functionality to drag drop controls between cells and swap those controls?
It would be feasible if the TLP is fixed size in rows and columns and not autosizing (because an empty row or column may disappear). And it may help to fill each cell with a Panel as parent of your controls, so you only have to swap the content of panels. Managing controls in the TLP cells themselves is a bit more complex. Come to think of it, when using a TLP in such a restricted way you might as well draw a grid of Panel controls yourself.
I have these DataGridViews, used pretty heavily in my app to show lists of child or summary data. The column widths are set to handle most cases, and to fit in the default size of the UserControls that directly contain and manage the DGVs (the UserControl also contains a title, sum of records, and a Refresh button).
I would like to give the user a menu option in one screen that has a LOT of DGVs, that would basically replicate the behavior they'd get if they double-clicked on the right border of each column header they saw. The default behavior in that case is to resize that column so that all text of all cells in the column is shown. This is a freebie of using DGVs, but I'd like to plug into it to do the same thing on a wider scale.
I DO NOT want to set the AutoSize property of the columns or DGVs; if a column is resized and the user wants to further adjust it, they should be able to. There has to be a way to do this without locking the column widths to what AutoSize thinks is necessary.
OK, finally I found it:
dataGridView.AutoResizeColumn(col.Index, DataGridViewAutoSizeColumnMode.AllCells);
or if you prefer to resize all columns in one shot:
dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnMode.AllCells);
I have a form in C# (WinForm). It looks like this:
(LOGO)
blank space for labels that I add
through code (I can fit 10 labels in
this space)
(close button)
The blank space can hold about 10 labels.
I am stumped on how I would make this form scrollable if I want to add 20 labels? If I add 20 labels via code, then the 11th label will overlap with my close button and the 12th+ label(s) will run off the end of the form.
How do I make just the blank space portion of my form scrollable where I am creating the labels? I don't want to use a listbox.
Thanks.
You should try using either a TableLayoutPanel or a FlowLayoutPanel as a container for your Label controls.
A TableLayoutPanel will allow you a finer level of control over where your labels are positioned. Like an HTML table, you specify the exact cell position (using row and column coordinates) of each control.
By contrast, a FlowLayoutPanel will handle the positioning of its contents automatically, either in a vertical or horizontal layout configuration. The positioning is determined by the order in which you add the controls, allowing you to achieve a dynamic layout with a minimal amount of fuss.
Either will allow you to add your label controls to it at run-time and size itself appropriately. In order for layout panel to be scrollable, make sure that you set its AutoScroll property to "True".
Maybe a FlowLayoutPanel with AutoScroll set to true and FlowDirection set to TopDown.
Place all controls inside a panel and use scrollbar control.
Understand .NET Scrollbars
You could use a FlowLayoutPanel.
Add as many labels you need and enable AutoScroll on the FlowLayoutPanel.
As I stated in title to this question - I have an WPF Grid based layout with two header rows and few empty ones. Grid has about 100 columns.
I am trying to achieve the situation, in which I will be able to highlight the cell of empty row, when mouse is over it (and fire an event, when user will click this cell).
I sketched my concept:
When the cursor is over the cell in the second row and third column, I would like to change the border of this cell and knowing the row and column number - change to borders of few other cells.
Thanks for any help.
What you'd usually do in such situation is to add a dummy UIElement,e.g. a Border, Rectangle (or a ContentControl that later could hold your actual content) that fills the cell completely and then on MouseMove query Grid.GetColumn Grid.GetRow on the hit UIElement. You can then loop through all children of your grid and change the borders where needed.
But if I look at your sample picture it seems that you want display a helper lines hinting row and column of your current cell. This can be easily done using Adorners. It is basically an additional layer on top of everything where you can place additional visuals that are bound to size and position of the coneceted control. You woould create an Adorner for the current cell (Border, ContentControl)