I have saved value of checkbox in database, now I want to populate these value into checkbox.
Let say, I want to checkbox checked or unchecked according to value in database.
If rowe(0).Item("offer_1").Value.ToString = "Yes" Then
Offer_1CheckBox.CheckState = CheckState.Checked
ElseIf rowe(0).Item("offer_1").Value.ToString = "No" Then
Offer_1CheckBox.CheckState = CheckState.Unchecked
End If
If rowe(0).Item("offer_2").Value.ToString = "Yes" Then
Offer_2CheckBox.CheckState = CheckState.Checked
ElseIf rowe(0).Item("offer_2").Value.ToString = "No" Then
Offer_2CheckBox.CheckState = CheckState.Unchecked
End If
If you have not any database exception , you can use below
You dont need any if statements and you should use Checked property
Offer_1CheckBox.Checked = rowe(0).Item("offer_1").Value.ToString = "Yes"
Offer_2CheckBox.Checked = rowe(0).Item("offer_2").Value.ToString = "Yes"
Related
I cant seem to figure out how to store unchecked checboxes value in my DB.
i have this in my view
{{Form::label('user_photo', 'Valodas',['class' => 'control-label'])}}
Latviešu {{Form::checkbox('val[]', 'Latviesu',false)}}
Angļu {{Form::checkbox('val[]', 'Anglu',false)}}
Krievu {{Form::checkbox('val[]', 'Krievu',false)}}
And here is my controller function to store data
if($req->input('val') == null){
$valoda = "";
} else {
$valoda = request('val');
}
And in my database im only getting the value of the values that are checked
I need the 3rd value so that in my update view i could set values to checked or unchecked for each value
If you have a column for each checkbox, you can do it this way;
$latviesu = array_has($req->val,'Latviesu')?1:0;
$anglu = array_has($req->val,'Anglu')?1:0;
$krievu = array_has($req->val,'Krievu')?1:0;
checking that the array from the request has the value
But to be honest, I would rename the checkboxes so that they are not in an array
Quick reminder in Laravel 5.6 You can check if checkbox is checked by
$request->has('yourCheckboxName'); / return true / false
A background to why im trying to do this.
I am creating a program for work, this is one of many way of doing this process, where users select test that they have carried out, around 50 possible test using a userform that I've made. From the selection it runs through each userform based off which checkboxes were ticked, without the need to choose another test.
i.e. if they select 1,2,5 then the program will eventually load UserForm1 -> UserForm2 -> NOT UserForm3 -> NOT UserForm4 -> UseeForm5
The idea is that the user selects the options they want then based off the options selected create an array of either 0 if they didn't select the option or (1,2,3,4...) if they did, this number depends upon which checkbox was selected. i.e CheckBox1 = 1 CheckBox2 = 2 etc.
From this array I think i'll be able to select the correct userform using the .find feature in excel with a for loop.
But I have an issue when I run my code below,
Sub List_Create()
Dim tests(5) As Integer
If CheckBox1.Value = True Then
tests(0) = 1
Else: tests(0) = 0
End If
If CheckBox2.Value = True Then
tests(1) = 2
Else: tests(1) = 0
End If
If CheckBox3.Value = True Then
tests(2) = 3
Else: tests(2)= 0
End If
If CheckBox4.Value = True Then
tests(3) = 4
Else: tests(3) = 0
End If
If CheckBox5.Value = True Then
tests(4) = 5
Else: tests(4) = 0
End If
End Sub
I get a
runtime 424 error object required.
Which when debugged is on the line If CheckBox1.Value = True Then
Where have i gone wrong with my code? Is this possible, im not sure if it is?
You need to explicitly reference the userform to evaluate the checkbox value.
If userformX.CheckBox1.Value = True Then
Simple code lines:
myGrid.Columns.Add("Question", "Question")
myGrid.Columns.Add("Answers", "Answers")
myGrid.Rows.Add()
myGrid.Rows(0).Cells("Question").Value = "dummy checkbox test"
Dim chk As New DataGridViewCheckBoxCell
chk.TrueValue = "1"
chk.FalseValue = "0"
myGrid.Rows(0).Cells("Answers").Value = "0"
myGrid.Rows(0).Cells("Answers") = chk
Will result in a "System.FormatException: Formatted value of the cell has a wrong type." when the form is executed.
Any idea why?
Thanks
You are formatting the cell as DataGridViewTextBoxCell at myGrid.Rows(0).Cells("Answers").Value = "0". Change the order of setting cell type and setting value processes like this:
myGrid.Rows(0).Cells("Answers") = chk
myGrid.Rows(0).Cells("Answers").Value = "0"
Or, you can simply add the "Answers" column as DataGridViewCheckBoxColumn if you are going to set true/false values to all the cells of the column:
myGrid.Columns.Add("Question", "Question")
Dim chkColumn As New DataGridViewCheckBoxColumn
chkColumn.Name = "Answers"
chkColumn.HeaderText = "Answers"
myGrid.Columns.Add(chkColumn)
myGrid.Rows(0).Cells("Question").Value = "dummy checkbox test"
myGrid.Rows(0).Cells("Answers").Value = false
I have the following structures:
class UserOther(ndb.Model):
other_type = ndb.StringProperty(indexed = True)
other_data = ndb.StringProperty(indexed = False)
class User(ndb.Model):
name = ndb.StringProperty(default = "NULL", indexed = False)
email = ndb.StringProperty(default = "NULL", indexed = False)
active = ndb.BooleanProperty(default = True)
others = ndb.StructuredProperty(UserOther, repeated = True)
updated_at = ndb.DateTimeProperty(auto_now = True)
How can I use an User key id and a string for other_type(like "job") to get and be able to edit that information. I tried using the ancestor parameter, but perhaps I didn't do that correctly.
user_key = ndb.Key("User", user_id)
user = user_key.get()
other = UserOther.query(UserOther.other_type == "job", ancestor = user_key).get()
So if i print my user looks like this :
1425436064.0User(key=Key('User', 5171003185430528), active=True, email=u'NULL', name=u'NULL', others=[UserOther(other_data=u'0', other_type=u'job'), UserOther(other_data=u'0', other_type=u'times_worked'), UserOther(other_data=u'0', other_type=u'times_opened')], updated_at=datetime.datetime(2015, 3, 6, 10, 35, 24, 838078))
But if I print the job variable it is
1425436759.0None
You've misunderstood how to query for structured properties. The UserOther entity doesn't live on its own, it's part of the relevant User entity, so that's what you need to query.
The documentation explains exactly how to do this, but in summary you would do:
job = User.query(User.others.other_type == "job").get()
What I would do is get the user (by id) and then filter the 'others' in code:
user = User.get_by_id(user_key_id)
for other in user.others:
if other.other_type == 'job':
print other.other_data # do edits
i am writing a script which reads the user details from active directory, it reads users samid and pull all his details in text boxes to display; here i am using a radio button to enable/disable all those textboes. That is radio button switches between 2 modes, readmode/writemode which enables and disables those text boxes so that they can be edited and changes can be committed.
Here is the issue, by default readmode radio button is checked and every text box is disabled, when i check the write mode button , everything gets enabled , but it stays there. when i check the readmode button again , it doesn't disable those boxes ; i tried form refresh , but it didn't work; please let me know if any alternatives.
function ReadAD( $object )
{
$TextBox2.Enabled = "False"
$TextBox3.Enabled = "False"
$TextBox4.Enabled = "False"
$TextBox5.Enabled = "False"
$TextBox6.Enabled = "False"
$TextBox7.Enabled = "False"
$TextBox8.Enabled = "False"
$TextBox9.Enabled = "False"
$RichTextBox1.Enabled = "False"
$Button4.Visible = "False"
$form1.refresh()
}
function WriteAD( $object )
{
$TextBox2.Enabled = "False"
$TextBox3.Enabled = "False"
$TextBox4.Enabled = "False"
$TextBox5.Enabled = "False"
$TextBox6.Enabled = "False"
$TextBox7.Enabled = "False"
$TextBox8.Enabled = "False"
$TextBox9.Enabled = "False"
$RichTextBox1.Enabled = "False"
$Button4.Visible = "False"
$form1.refresh()
}
The Enabled and Visible properties takes a bool, not a string. bool in PowerShell is $true and $false. Try this:
$TextBox9.Enabled = $false
$RichTextBox1.Enabled = $false
$Button4.Visible = $false
There's no need to refresh, doevents etc. At least everything works perfectly when I test it by only changing the bool value like above.