I have a picker:
<Picker Title="Status" x:Name="pickerStatus">
<Picker.Items>
<x:String>In Progress</x:String>
<x:String>Completed</x:String>
<x:String>Dropped</x:String>
<x:String>Plan To Take</x:String>
</Picker.Items>
The required value is already stored in a database as a Text value. How do I display a picker
on an editable page to load that selected text value from the database into the edit page picker?
I've tried:
pickerStatus.SelectedItem = _courseObject.Status;
This approach is made for code-behind, if you intend to use ViewModels I can provide a more in-depth answer. But for your case this works:
List<string> pickerStates = new List<string>
{
"In Progress",
"Completed",
"Dropped",
"Plan To Take"
};
pickerStatus.ItemsSource = pickerStates;
pickerStatus.SelectedIndex = pickerStates
.FindIndex(status => status == _courseObject.Status);
Related
I have a question,is it possible to render labels or buttons or any UI element on the form dynamicaly?
for Eg:
I am building a Mobile app which is replicate of my website, so the pages and fields will be same the UI will be different.
if on the website i add a new field in a form, so can i add that field directly to my Mobile Form without coding anything?
So Basically i want to store it in the Database, and when loading the page fetch the values and render the UI.
Is this Possible with Xamarin forms?
StackLayout sl = new StackLayout();
// controls is an IEnumerable of control types
foreach(var s in controls) {
switch (s.ControlType) {
case "Label":
sl.Add(new Label() { Text = s.Caption });
break;
case "Textbox":
sl.Add(new Entry());
break;
case "Button":
sl.Add(new Button() { Text = s.Caption });
break;
// add additional cases for whatever types of controls you want to support
}
}
Yes. This is possible. You can store Xamarin Forms XAML in the database, and render that XAML dynamically without writing code. The answer above will work, but it's not an elegant solution because you will need to write code.
If you clone this repo, there is a sample for rendering XAML dynamically:
https://github.com/MelbourneDeveloper/Adapt.Presentation.git
You can store the XAML in the database and use this method to load the UI.
I have a Telerik MVC (not Kendo) grid that uses the default Ajax binding for editing. For some unfathomable reason, when editing a row, the Save and Cancel buttons sport a tooltip of "Edit". I have not found where to define the Title text for the Save or Cancel buttons, only for the Edit and Delete buttons:
commands.Edit().ButtonType(GridButtonType.BareImage).HtmlAttributes(new { #class = "grid-edit-button" }).ImageHtmlAttributes(new { #alt = "Edit", #title = "Edit" });
commands.Delete().ButtonType(GridButtonType.BareImage).HtmlAttributes(new { #class = "grid-delete-button" }).ImageHtmlAttributes(new { #alt = "Delete", #title = "Delete" });
This is code that I copied from another section of the project (unfortunately, written by someone who has since left the company) and it works correctly there. I have had no luck asking Telerik for help, as the MVC libraries are not their most current offerings (but I must use them for legacy reasons).
Does anyone know how to force the tool-tip text to the correct value?
There may be better solutions, but I wound up fixing it through some Javascript trickery (this is what is used by the other instances of this grid. I'd missed it because I had custom edit code for handling the dropdown boxes):
In the grid definition:
.ClientEvents(events => events.OnDataBound("defaultGridDataBound").OnEdit("defaultGridEdit"))
And then:
function defaultGridEdit(e) {
var $form = $(e.form);
if (e.mode == "insert") {
$form.find(".t-grid-insert .t-insert").attr("title", "Save");
$form.find(".t-grid-insert .t-insert").attr("alt", "Save");
}
else {
$form.find(".t-grid-update .t-update").attr("title", "Save");
$form.find(".t-grid-update .t-update").attr("alt", "Save");
}
$form.find(".t-grid-cancel .t-cancel").attr("title", "Cancel");
$form.find(".t-grid-cancel .t-cancel").attr("alt", "Cancel");
}
I am using kendo grid and its build-in functionality for creating and updating items.
I'm looking for a way to change Editor labels (title and buttons Update/Cancel).
I found an answer here (Change Button text in Kendo Ui Grid Popup Window) where OnaBei explains how to change title.
However, I still cannot figure out the way to change button names based on whether item is being added or being edited. The same with title, is it a way to change it based on "create"/"update" state?
I assume that it can be done with javascript, but it will probably be a hack and dirty solution.
This can be done in the edit event of the grid. The model event argument has a isNew method which will return true in "create" state. Here is some sample code:
edit: function(e) {
var title = "Edit mode";
if (e.model.isNew()) {
title = "Insert mode";
}
var wnd = e.container.data("kendoWindow");
wnd.title(title);
}
And a live demo: http://jsbin.com/USUpAZUT/1/edit
I'm trying to achieve a very common scenario whereas given a list of options to choose from, the last one says "Other" and when selected the user is presented with the input field to specify what "other" is.
In my case, it's a list of Person's titles:
public List<string> TitleList
{
get
{
return new List<string> { "Mr", "Mrs", "Miss", "Dr", "Other" };
}
}
and what I'm trying to do is this:
#Html.DropDownListFor(m => m.Title, new SelectList(Model.TitleList), "Please select...") #Html.TextBoxFor(m => m.Title)
I want the model to bind the TextBox value when "Other" is selected in the DropDownLis, and bind to selected item in DropDownList in all other cases.
Is this achievable without adding an extra property on the Model?
a better solution is not to bind to two fields, instead, copy selected item from a drop-down into bound textbox with some clever javascript:
#Html.DropDownList("ddlTitle", new SelectList(Model.TitleList), "Please select")
#Html.TextBoxFor(m => m.Title, new { maxLength = 10 })
Javascript:
ToggleTitleFields = function () {
var title, txtTitle;
title = $('select#ddlTitle').val();
txtTitle = $('input#Title');
if (title === "Other") {
txtTitle.val("");
txtTitle.show();
return txtTitle.focus();
} else {
txtTitle.hide();
txtTitle.val(title);
return $('span[data-valmsg-for="Title"]').empty();
}
};
$(document).on("change", "select#ddlTitle", function(e) {
return ToggleTitleFields();
});
hope this helps somebody
found a client-side solution: add/remove the "name" attribute from DropDownList. Here's my coffee script:
ToggleTitleFields = () ->
if $('select#Title').val() == "Other"
$('select#Title').removeAttr('name')
else
$('select#Title').attr('name','Title')
Tsar,
Being honest, this isn't a scenario that I've had to deal with before, but is nonetheless a good one. If I were faced with this dilemma and was allowed to use a javascript solution, i'd present a previously 'hidden' textbox when other was chosen. The user would then have to enter the new value into this texbox, which on loosing focus would populate the selectlist and be selected. Then when the form was submitted, you'd have this new value still as part of the exisiting model.
Of course, you could also do a similar logic of showing the textbox when selecting other but this time, do a little logic on the httpost controller action to determine if the 'other' item was selected and then populate the model from the 'textbox' value.
Of course, both scenarios would need a heap of validation, but in principle, either approach would 'work'
I'm having a WinForm on witch I've a DataGridView that display a list of sites. bellow that grid i've a TextBox and a Combobox, using DataBinding the textbox show the current value "Code" grid column and the combobox show the province. The combobox is filled with a list for province
The weird thing is this:
When I change the combobox selected province for another one, at the time when the focus leave the combobox, the original value of the of the combobox return. I can't find a way for the combobox to keep the changed value.
what am I doing wrong?
Here my the code of my workbench project;
private void Form1_Load(object sender, EventArgs e)
{
context = new GMR_DEVEntities();
lSite = from t in context.tblSites where t.Actif == true select t;
this.dataGridView1.DataSource = lSite;
this.dataGridView1.AutoGenerateColumns = true;
Guid ProvinceId = Guid.Parse("00000000-0001-0000-0008-000000000001");
IQueryable<tblDomVal> provinces = from prov in context.tblDomVals where prov.pTypeDomValID == ProvinceId select prov;
comboBox1.DataSource = provinces;
comboBox1.ValueMember = "ID";
comboBox1.DisplayMember = "DescrFr";
textBox1.DataBindings.Add(new Binding("Text", lSite, "Code"));
comboBox1.DataBindings.Add(new Binding("SelectedValue", lSite, "pProvinceID", false, DataSourceUpdateMode.OnPropertyChanged));
}
Any help would be welcome :)
Hugo
Try creating a new binding context for you combo
BindingContext oBC = new BindingContext();
comboBox1.BindingContext = oBC;
comboBox1.DataBindings.Add(new Binding("SelectedValue", lSite, "pProvinceID", false, DataSourceUpdateMode.OnPropertyChanged));
While searching for a solution, I've discover that the problem have something to do with the Datatype (All my tables IDs are GUID), I've change the Binding to bind with a varchar field instead of the guid, and thing went good. So the problem have something to do with GUID. But I'll change my approach, and work with manual bind