VB .Net Disable user row resize on datagridview - vb.net

I am filling Datagridview with dataset and Datagridview has all resize properties set to false but, user can even resize rows. How could I disable it?
MyDatagridView.AllowUserToAddRows = False
MyDatagridView.AllowUserToResizeRows = False
MyDatagridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
...

I realize that this is an old post, but I had exactly the same problem. The AllowUserToResizeRows property may be overridden by the MyDatagridView.RowTemplate.Resizable setting. Try setting both to False, solved the problem for me.

In my experience,
MyDatagridView.AllowUserToResizeRows = False
does always prevents user to resize a row. I don't remember a case when it would be overriden by another property setting (and I use DataGridViews a lot). So I would say the line is not processed (you can debug it) or it is overriden by another setting later (track property value and see when it gets changed).
And by thew way, you can set it in the Datagridview Properties in VisualStudio, to make it a default setting.

Related

VB .NET - Autosize datagridview row height

Problem Definition
So I am trying to do something that should be very basic; however, I can't seem to make it actually work. I am simply trying to make my datagridview autoresize every row height to the text entered. Am I missing something?
What I have tried
I have read through examples on SO and other sites and they all recommend a similar idea. So to make it simple here is exactly what I have done so far:
I created a new datagridview.
I clicked on columns > Add and use the default name and type (textbox)
I kept the Autosizemode of that column at None and DefaultCellStyle WrapMode to True.
I changed the datagridview's AutoSizeRowsMode = AllCells
From there I build my project and type some data in, but the column simply grows the column width and not the row height:
Am I missing a step somewhere? I purposely put every step I did because I feel like I am just missing something very simple...
go to the data grid view -->properties --> default cell style-change the wrap setting to true then use the autosizerow property as any mode like allcells or display cellslike

wxPropertyGrid::EditorValidate() always returns true

A user is editing a value in a property grid, then he clicks a button outside the property grid which executes code to read the property values. Sometimes the OLD value of the property is read, rather than the new value which was being edited. I have to tell the users that they must complete the editing, by hitting return or clicking on another property before clicking any buttons outside the grid. They forget, and report a bug.
I would like to make this foolproof. Perhaps by forcing the current edit to complete when the mouse leaves the property grid.
I know how to handle the mouse leaving event. I do not know how to force the property grid to accept any partial edits.
I have tried, as a hint to the user,
pg = new wxPropertyGrid( ...
....
if( ! pg->EditorValidate() )
{
SetStatusText("Please complete editing");
return;
}
but EditorValidate() always returns true
Found it!
wxPropertyGrid::CommitChangesFromEditor()
http://docs.wxwidgets.org/trunk/classwx_property_grid.html#a6e06d92a622237457fea00372df1eaae

Run through all the controls in a form

I have a form and I am running through all the controls in that form.
My code is OK and is get all the controls with all their properties.
So for example I have a TabControl with 2 TabPages and 2 textboxes in each tabPage.
The problem is that for the tabPage that isn't selected , the textboxes' property visible is False, although I have set it to True.
I tried to solve this problem with Control.Select and Control.Focus , but Visible is still False:
Private Sub createXML(ByVal cnt As Control, ByVal elem As XElement)
Try
cnt.Select()
cnt.Focus()
Select Case cnt.Controls.Count
Case Is = 0
'Code here to write XElement to an XDocument
'Check Controls properties
Case Is > 0
For Each childCnt As Control In cnt.Controls
childCnt.Select()
childCnt.Focus()
Dim childElem As New XElement(childCnt.GetType.ToString)
Select Case childCnt.Controls.Count
Case Is = 0
'Code here to write XElement to an XDocument
'Check Controls properties
Case Is > 0
createXML(childCnt, childElem)
End Select
Next
End Select
Any ideas?
Note that I don't know what controls I have to run through each time
Your problem in this case is that a TabControl sets everything to invisble unless they are present in the currently selected tabpage. And when you change tab the controls are set to visible and previous ones dissapeares. So how does the tabcontrol keep track of a control that is manually set to visible false, so that it doesn't light up when the tab is changed? Well the visible property is not really based on a boolean value. It's merely an easy way to interpret it for us programmers. Either you see it or you don't, no rules to keep in mind or settings to mess up. Visible or not simple as that.
So what to do with your issue. Basically, my first thought when I see this is that you want to create a "open the program so it looks the same as when it was closed"-function. Which of course is not working properly at the moment since your parser probably set everything to visible=false, which at previously stated means not visible ever. Hence not showing after Tab control page change when loaded.
So solutions:
1. Add a tag to the controls in the tab control. This way you can look for the tag when saving. If it's there, set the visible property to true. (Easy to understand for you when maintaining in the future)
2. Use reflection to get the actual visible state. Look at SO thread and read about reflection: Using control.Visible returns False if it's on a tab page that is not selected (Not so easy to understand when maintaining in future)

Cell in Devexpress Treelist is set to editable yet it won't let me edit

I am using a DevExpress (10.2) Treelist in my VB.Net project in Visual Studio 2008. I currently have a treelist with TreeList.OptionsBehavior.Editable = True. I have two columns were the first one is AllowEdit = False. The second column I am setting the AllowEdit and ReadOnly dynamically though the action FocusedNodeChanged.
Within the FocusedNodeChange subroutine I check if a specific value is in the row and if so I set it to be editable or non-editable. I am setting it to be editable with:
treeList.Columns("field_name").OptionsColumn.ReadOnly = False
treeList.Columns("field_name").OptionsColumn.AllowEdit = True
and setting it to readonly with:
treeList.Columns("field_name").OptionsColumn.ReadOnly = True
treeList.Columns("field_name").OptionsColumn.AllowEdit = False
This works to a degree. Right now if I go in the editable cell in the treelist the cursor appears and blinks so I know it is editable and if I go in the cell when the un-editable row is focused the cursor doesn't blink.
However even though the cursor blinks I am unable to type. When I click on keys (numbers and letters) on the keyboard nothing is written.
SOLVED
Simple solution. The stored procedure I was using to fetch the data into the table didn't contain the field for the particular column I was trying to make editable and not editable. This was because it was a new value that was insert/updated differently than normal. To fix this I fetched null and/or 0 and it worked fine.
The code you are using is not quite correct. The best solution is to handle the TreeList's ShowingEditor event and set the e.Cancel parameter accordingly. To determine the current cell, use the TreeList's FocusedColumn and FocusedNode properties.

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