Setting a Datagrid Column to read only during run time - vb.net

I have a datagrid, not a datagridview, where I wan to make a column read only if radio button is checked or not.
So I define the column dynamically from a sql query:
Dim bool_col As New FormattableBoolColumn
bool_col.HeaderText = "Bool Colunm"
bool_col.MappingName = "bool_col"
Also on the form are two radio buttons, lets call them A and B.
When A is checked I want to set the bool_col to read only is true.
When B is checked I want to set the bool_col to read only is false.
Let me know if anything else is needed. I'm using the Click event but I can't figure out how to find the column in the Datagrid and set it to read only. Spent all afternoon trying to do that and searched everything I can think of with no luck.
And I can't change it to a datagridview unfortunately. Time and and money constraints on the project prohibit this.
Thanks in advance!

When you create the column you can add a check:
bool_col.ReadOnly = RadioButtonA.Checked
So the read only property of the column will be true if A is checked and false if A is not.
Now this assumes that your radio buttons are in a group so only one of the two can be checked at a time.
If the radio buttons are not in a group then use:
If RadioButtonA.Checked Then
bool_col.ReadOnly = true
else if RadioButtonB.Checked Then
bool_col.ReadOnly = false
End If

Related

Disallowing textbox editing if a ComboBox in the same Form is not filled (for each row individually) [duplicate]

I am working on an Access 2010 form which where the user can select a record in the form header via a combobox and then build up elements related to the selected record in the detail section of the form. The default view of the form is set to continuous forms.
One of the controls in the detail section of the form is a combobox control. What I want to do is set the enabled property of a textbox on the same row of the form to false based upon a selection from the combobox. The code I am running is:
If Me.cboElementType = "Contract Shrink" Then
Me.txtElementID = ""
Me.txtElementID.Enabled = False
EndIf
This works, but it sets all instances of the textbox (txtElementID) to enabled = false. What I want to have happen is for the txtElementID to have a different enabled setting for each row in the detail section based upon the selection of the combobox cboElementType. So, if cboElementType = "Contract Shrink" on row 1 of the scrolling detail section, the txtElementID.Enabled would be set to false for that row. If cboElementType = "Cost Group" on row 2 of the scrolling detail section, then I'd like txtElementID.Enabled to be False on row 1 of the detail section and txtElementID.Enabled to be True on row 2.
Can anyone confirm or deny that this can be done and, if it can be done, how you would suggest it be accomplished? No matter which way this goes, thanks for help.
You cannot do it through VBA like you did, you need to use Conditional formatting, there you have an option to set the Enabled property.
try in Form_Current() event like
Private Sub Form_Current()
If Me.cboElementType = "Contract Shrink" Then
Me.txtElementID = ""
Me.txtElementID.Enabled = False
EndIf
end sub
I have been searching for days for how to access an individual record on continuous form and I am willing to say it is not possible, but I have a trick that I will share here. I have an investments database, user gets in and writes a proposal and then there is a meeting where either the project is approved (given money) or it is cancelled. However, there are many more states a project can be in, Proposal, Execution, etc. but only Approved/Cancelled can happen at this stage. I created a MockBool field in the Project table. I put that on the continuous form and when the form is closed I run this:
rs_frm=me.recordset
rs_frm.movefirst
while not(rs_frm.eof)
if rs_frm("MockBool") then
rs_frm.edit
rs_frm("ProcessStatus")="Cancelled"
rs_frm("MockBool")=false
rs_frm.update
end if
rs_frm.movenext
wend
I had days of searching and had an epiphany so I thought I would share.

Conditional visibility on MS Access Form - how to write in VBA or Macro

I have some very (very) basic MS Access knowledge. I'm trying to expand a bit into either VBA or macros as I'd like to put in some conditional visibility for my form. Basically, I have a checkbox. If it's checked, I want three or four more fields to pop up. Someone was able to point me to a basic VBA formula of if (this checkbox) = true then, (fieldx).visible = true, else, (fieldx).visibility = false, end if.
But I'm so new to this that I need more help and explanation. I tried putting it in but couldn't get it to work (no error message, just nothing changed at all).
Specific questions:
-Does this formula seem right?
-If I want multiple fields to be visible, can I combine them into one formula or should I create a new "if" statement for all?
-Where do I enter this code? I'm running the Office 365 version. For all I know, I'm not even putting it in the right place.
-How do I determine the field names to replace the (this checkbox) and (fieldx) in the formula? I tried entering the name I title the fields as, but with the spaces in the name I got an error message, and without the spaces nothing happened. Is there a specific naming convention to turn the field names into formula-appropriate titles? Is the name listed somewhere?
-Once I get the formula entered, is there something I have to do to get it to run/take effect? I tried saving, closing and reopening with no changes.
-Is this the best way to go about this?
If there's anything else you think I should know, I would love to hear it - but please keep in mind I'm very new to this so if you could keep it at "dummy" or ELI5 levels of explanation, I'd appreciate it!
after creating a form with 4 textboxes and a checkbox put the form in design mode (lower right corner has design mode selected, select a textbox and hit property sheet on the ribbon (or f4).
On the property sheet note the visible property. set the visible property to false. Now the textbox will be invisible when the form starts.
Tip you can select all the textboxes at the same time and set their properties all at once.
Every control on the form and even the various parts of the form have properties you can set and play with. For instance you can give any name you want to any control. On the property sheet go to the other tab and set the name property.
Tip: choose a name you you will remember without having to look it up and describes the controls function.
Next select the checkbox (not the checkbox's label). On the property sheet go to the event tab and select the on click event. hit the ellipsis and choose code builder. Access is Event Driven. We want the textboxes to appear when the checkbox is selected so we put that code in the checkbox click event.
after choosing code builder we get the code window where we can browse among all the events for all our forms. for now all you should see is something like:
Private Sub mycheckbox_Click()
End Sub
So insert some code to handle the checkboxes like:
Private Sub mycheckbox_Click()
If mycheckbox = True Then
txtbox1.Visible = True
txtbox2.Visible = True
txtbox3.Visible = True
txtbox4.Visible = True
Else
txtbox1.Visible = False
txtbox2.Visible = False
txtbox3.Visible = False
txtbox4.Visible = False
End If
End Sub
now when the checkbox is not checked no textboxes are visible.
but when the checkbox is checked they appear

Select combobox intem after bounded with SQL Query in Access

I have the following pair of combobox that are used for two inserts in two different access tables from a single form.
The problem I have is that I am not able to make anything else load the form is selected both in Name_OT and in Year the first value that contains corresponding combobox.
I think the solution is with:
Combobox1.Selected (0) = True 'First value
But the combobox goes blank, no text or anything appears.
Solved with this
Cuadro_combinado79 = Cuadro_combinado79.ItemData(0)
Cuadro_combinado85 = Cuadro_combinado85.ItemData(0)

VB.net checking if active control is specific DGV

I need to check if my Current DGV is a specific datagridview in my program named DgvDiameterData, so how do I preform this check?
I got this code which sets the active current DGV which works but the check doesnt and no idea how to get it to work
Dim CurrentDGV As DataGridView = ActiveControl
If CurrentDGV = DgvDiameterData Then 'the part after the = doesnt work
End If
Have a look at the Is Operator.
From the link:
The Is operator determines if two object references refer to the same object
So you need:
If CurrentDGV Is DgvDiameterData Then
This is less foolproof but you could also check the Name property.
If CurrentDGV.Name = DgvDiameterData.Name Then

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.