changing the position of textbox using code - vb.net

In my form I have an AXVS Flex Grid and a Textbox. Firstly the textbox will not be visible.
When the focus is on a particular column of the flexgrid, the textbox will be visible and the Flex Grid will be disabled. The position of the text box will be at the bottom of the particular row at the first time.
But when another row is inserted, then I need to change the position of the textbox to the bottom of the new row and so on.
How can I do that? Thanks in advance.

Position of a control can be retrieved and set using the Top & Left properties of the control.
So you can get the Top,Left property of the inserted row and set the Top,Left property of TextBox accrodingly.
e.g.
TextBox1.Top = InsertedRow.Top +=10
TextBox1.Left = InsertedRow.Left
This will bring the textbox below inserted row.

Related

Access Form Scrollbars won't disappear when not needed

I have multiple continuous sub-forms in a single parent form. When the number of records in the subform is small enough that the scrollbar is not need, it disappears but leaves behind a white space where it would usually be if drawn. If the subform originally is opened with the small number of records, there is no graphical issue. Seems to be a refresh/repaint issue but that isn't working. Any pointer in the right direction would be greatly appreciated! Have read that it may have to do with margins/anchors but all steps down that path have turned up nothing.
Another way to handle this is to essentially reload the sub-form by...
Save the SQL string representing for the recordsource property of the sub-form to a string variable.
Set the SourceObject property of the sub-form container to "".
Set the SourceObject property of the sub-form container back to the original name.
Set the recordsource property of the sub-form = to the string variable in step 1.
This should remove the grey area previously occupied by the scroll bar.
Check the record count. Set the scroll bar accordingly...
Me.Scrollbars = 0 ' to not show them.
Me.Scrollbars = 1 ' for horizontal only
Me.Scrollbars = 2 ' for vertical only
Me.Scrollbars = 3 ' for both horizontal and vertical

VB.Net - Is there any way to count the number of selected rows in a datagridview?

I need to display the number of rows selected in a DataGridView to a label whenever the user selected at least one. But I have no idea on how to do it. Also I want to know what event should I use.
To get the number of selected rows, you may use
Int32 selectedRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected)
And then to display in in a label;
lblLabel = selectedRowCount.ToString()
you need to set YourGridView.MultiSelect=true; MultiSelect When the MultiSelect property is set to true, multiple elements (cells, rows, or columns) can be selected in the DataGridView control. To select multiple elements, the user can hold down the CTRL key while clicking the elements to select. Consecutive elements can be selected by clicking the first element to select and then, while holding down the SHIFT key, clicking the last element to select.
then you can use SelectRows.
MessageBox.Show(yourDataGridView.SelectedRows.Count.ToString());
The Event you are looking for is the SelectionChanged event of the grid.
You should set the MultiSelect property of the grid to true to allow multiple selections.
And to get the number of selected rows you can use the SelectedRows property:
MyLabel.Text = MyGrid.SelectedRows.Count().ToString()
Data Grid Mouse Down Event
Dim CRow As Int32 = DataGridView.HitTest(e.X, e.Y).RowIndex
DataGridView.Rows(CRow).Cells(ColumnName).Value()

WinForms TableLayoutPanel ComboBox not resizing properly

I'm trying to use a TableLayoutPanel to align a few controls on a form next to their labels like so:
Label1 [combobox ]
LongerLabel [longer combobox]
But when I run the project and grab the right hand side of the form and shrink the form, the combobox doesn't resize, it gets cut off... Now, I were to not use the TableLayoutPanel, but just anchor a combobox to a form's edges, it will resize properly. What am I doing wrong with the TableLayoutPanel?
I found the answer here:
http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.windowsforms.controls/2006-12/msg00209.html
So I set the first column with the label to autosize (I have the label fill docked in the cell and the text alignment set to middle left). Then dock fill the combobox in the second column. Then, set the second column's size type to 100%, NOT autosize. I don't know why it works, but it does.

is it possible to anchor a control to another control?

Is it possible to anchor a control to another control?
Lets say i want my Button1 to keep its 4px distance from Textbox1 control without
using FlowLayoutTable control?
"Why would be this advantageous?" - one could ask
Well let's say you have a SplitContainer with a vertical splitter and you have Textboxes
in SplitContainer.Panel1 which are anchored to the left and right but their maximum size's
width is smaller than you allow to the SplitContainer.Panel1's width to have (maybe
because you want text to show up there or because additional padding or whatever,you name it)
Now let's say you also have a button next to Textbox1 and you dont want Textbox1 to be
overlapped by the Button1 because its extends to far.
If i want to have my textbox fill the SplitContainer.Panel1 in a fashion that it leaves space for
Button1 control while still both of them are anchored to the right how would i do it?
I extensively use TableLayoutPanels and FlowLayoutPanels to accomplish this. For you specific circumstance I would use a TableLayoutPanel with three columns and a row for each TextBox.
Column 1: Auto-width, contains Labels all with AutoSize = True.
Column 2: 100% width, contains TextBoxes all with Anchor = Left, Right.
Column 3: Auto-width, contains the Button in the appropriate row.
Next, I set all text boxes, except for the one next to the button, ColumnSpan = 2. Then just put the TableLayoutPanel in the SplitPanel and set Dock = Fill.
it will be a sequence in live which should be flow out from left and keep working lets the right side should be layout.
List item safty cares should be provided.
List item all things that use in this method should be provided and be check;

DataGridView - how to hide the "new" row?

My DataGridView is read-only - the user cannot enter data into it, so that empty row at the end (the "new" row?) just looks ugly.
How can I prevent it from displaying?
On the form designer view, click the little arrow to the right on the DataGridView. Adjust the value for Enable Adding. That will remove the row at the bottom of your grid.
Programmatically, you can adjust the AllowUserToAddRows property.
myGrid.AllowUserToAddRows = False
The DataGridView has a boolean property AllowUserToAddRows. Set this to false and you should no longer see the empty row at the end of the grid.
Just a clarification for other people who are looking at this for WPF the datagrid property has been renamed to CanUserAddRows