Select ID from Picker - xamarin.forms

I am getting values in picker from an API, text and Value are two fields as I declared ! I am able to see values in it ! I want that whenever I select item from It, I am able to fetch respective value of that field !
async void CallInspectionMaster()
{
string Url = "192.168.xx.xx/api/QMSin/GetInspectionMasterList";
var data = await Url.GetJsonAsync<List<MyClass>>();
InspectionMasterPicker.ItemsSource = data;
InspectionMasterPicker.ItemDisplayBinding = new Binding("Text");
Binding selecteditemx = new Binding("InspectionMaster");
selecteditemx.Mode = BindingMode.TwoWay;
selecteditemx.Source = InspectionMasterPicker;
}
public class MyClass
{
public string Value { get; set; }
public string Text { get; set; }
}
I have to display text but fetch value so I can pass it other functions ! How do do that ?

assign a handler to the SelectedIndexChanged event
InspectionMasterPicker.SelectedIndexChanged += PickerSelect;
then create the handler
protected void PickerSelect(object sender, EventArgs args)
{
var item = (MyClass)InspectionMasterPicker.SelectedItem;
...
}
there is a complete example included in the docs

Related

Select many CheckBox on GridPanel Ext.Net (ASP.NET)

How to select Rows on GridPanel using ext.net Library on ASP.NET.
When i put this code on Page_Load event, it's work fine :
protected void Page_Load(object sender, EventArgs e)
{
RowSelectionModel sm = gridRolesPermission.GetSelectionModel() as RowSelectionModel;
sm.SelectedRows.Add(new SelectedRow(1));
sm.SelectedRows.Add(new SelectedRow(2));
}
but when i would to select CheckBoxs on Ajax event, it's not working !
[DirectMethod]
public void FillPermissionForSelectedRole()
{
RowSelectionModel sm = gridRolesPermission.GetSelectionModel() as RowSelectionModel;
sm.SelectedRows.Add(new SelectedRow(1));
sm.SelectedRows.Add(new SelectedRow(2));
}
On view :
....
<Listeners>
<Command Handler="App.direct.FillPermissionForSelectedRole();" />
</Listeners>
...
Any Help Please !
In your example,when u click the button(directMethod button),a pamatercollection sent to the server called CheckboxSelectionModel1 .on server side, u can get the this parameter collection like this.
string hh= HttpContext.Current.Request["CheckboxSelectionModel1"];
*CheckboxSelectionModel1 is the model name of the grid on your example.
in your case like that
[DirectMethod]
public void FillPermissionForSelectedRole()
{
string hh= HttpContext.Current.Request["CheckboxSelectionModel1"];
}
string hh should be something like this depents on the what u checked on grid.
"[{"RecordID":5,"RowIndex":5},{"RecordID":7,"RowIndex":7},{"RecordID":3,"RowIndex":3}]"
later u can desrialize this string and get the RecordID something like this
var rw = JSON.Deserialize<Row[]>(hh);
string txt = "";
foreach (var item in rw)
{
txt += item.RecordID;
}
and the row class
public class Row{
public string RecordID { get; set; }
public string RowIndex { get; set; }
}
to resolve this probleme i should add this line to upadate modifications :
sm.UpdateSelection();

Accessing OutArgument value of Receive implementation child activity within custom WF4 activity

Using VS2012/.NET 4.5 I am creating a custom activity which implements a Receive child activity (as an implementation child). The parameters are in the example below fixed to just one: OutValue of type Guid.
I really would love to access the value of incoming parameter value in ReceiveDone, because I need to work with it and transform it before returning it from the activity. Please ignore that I am currently using a Guid, it still fails to access the value with and InvalidOperationException:
An Activity can only get the location of arguments which it owns. Activity 'TestActivity' is trying to get the location of argument 'OutValue' which is owned by activity 'Wait for
workflow start request [Internal for TestActivity]'
I have tried everything I could think of, but am stupefied. There must be a way to do this very simple thing?
public class TestActivity : NativeActivity<Guid>
{
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
var content = ReceiveParametersContent.Create(new Dictionary<string, OutArgument>()
{
// How to access the runtime value of this inside TestActivity?
{"OutValue", new OutArgument<Guid>()}
});
startReceiver = new Receive()
{
DisplayName = string.Format("Wait for workflow start request [Internal for {0}]", this.DisplayName),
CanCreateInstance = true,
ServiceContractName = XName.Get("IStartService", Namespace),
OperationName = "Start",
Content = content
};
foreach (KeyValuePair<string, OutArgument> keyValuePair in content.Parameters)
{
metadata.AddImportedChild(keyValuePair.Value.Expression);
}
metadata.AddImplementationChild(startReceiver);
}
protected override void Execute(NativeActivityContext context)
{
context.ScheduleActivity(startReceiver, ReceiveDone);
}
private void ReceiveDone(NativeActivityContext context, ActivityInstance completedInstance)
{
var receive = completedInstance.Activity as Receive;
ReceiveParametersContent content = receive.Content as ReceiveParametersContent;
try
{
// This causes InvalidOperationException.
// An Activity can only get the location of arguments which it owns.
// Activity 'TestActivity' is trying to get the location of argument 'OutValue'
// which is owned by activity 'Wait for workflow start request [Internal for TestActivity]'
var parmValue = content.Parameters["OutValue"].Get(context);
}
catch (Exception)
{ }
}
private Receive startReceiver;
private const string Namespace = "http://company.namespace";
}
Use internal variables to pass values between internal activities.
Although not directly related to your code, see the example below which should give you the idea:
public sealed class CustomNativeActivity : NativeActivity<int>
{
private Variable<int> internalVar;
private Assign<int> internalAssign;
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
base.CacheMetadata(metadata);
internalVar = new Variable<int>("intInternalVar", 10);
metadata.AddImplementationVariable(internalVar);
internalAssign = new Assign<int>
{
To = internalVar,
Value = 12345
};
metadata.AddImplementationChild(internalAssign);
}
protected override void Execute(NativeActivityContext context)
{
context.ScheduleActivity(internalAssign, (activityContext, instance) =>
{
// Use internalVar value, which was seted by previous activity
var value = internalVar.Get(activityContext);
Result.Set(activityContext, value);
});
}
}
Calling the above activity:
WorkflowInvoker.Invoke<int>(new CustomNativeActivity());
Will output:
12345
Edit:
In your case your OutArgument will be the internalVar
new OutArgument<int>(internalVar);
You need to use OutArgument and them to variables. See the code example with the documentation.
I may have tried everything I thought of, but I am stubborn and refuse to give up, so I kept on thinking ;)
I here have changed my example to use a Data class as a parameter instead (it does not change anything in itself, but I needed that in my real world example).
This code below is now a working example on how to access the incoming data. The use of an implementation Variable is the key:
runtimeVariable = new Variable<Data>();
metadata.AddImplementationVariable(runtimeVariable);
And the OutArgument:
new OutArgument<Data>(runtimeVariable)
I can then access the value with:
// Here dataValue will get the incoming value.
var dataValue = runtimeVariable.Get(context);
I haven't seen an example elsewhere, which does exactly this. Hope it will be of use to any one but me.
The code:
[DataContract]
public class Data
{
[DataMember]
Guid Property1 { get; set; }
[DataMember]
int Property2 { get; set; }
}
public class TestActivity : NativeActivity<Guid>
{
public ReceiveContent Content { get; set; }
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
runtimeVariable = new Variable<Data>();
metadata.AddImplementationVariable(runtimeVariable);
Content = ReceiveParametersContent.Create(new Dictionary<string, OutArgument>()
{
{"OutValue", new OutArgument<Data> (runtimeVariable)}
});
startReceiver = new Receive()
{
DisplayName = string.Format("Wait for workflow start request [Internal for {0}]", this.DisplayName),
CanCreateInstance = true,
ServiceContractName = XName.Get("IStartService", Namespace),
OperationName = "Start",
Content = Content
};
metadata.AddImplementationChild(startReceiver);
}
protected override void Execute(NativeActivityContext context)
{
context.ScheduleActivity(startReceiver, ReceiveDone);
}
private void ReceiveDone(NativeActivityContext context, ActivityInstance completedInstance)
{
// Here dataValue will get the incoming value.
var dataValue = runtimeVariable.Get(context);
}
private Receive startReceiver;
private Variable<Data> runtimeVariable;
private const string Namespace = "http://company.namespace";
}

DataBinding a DateTimePicker raises "DataBinding cannot find a row in the list that is suitable for all bindings."

I have a simple test application which reproduces an error I encountered recently. Basically I have a simple WinForm with databound TextBox and DateTimePicker controls, and a button. When I execute the code below (on the button click), I get the error "DataBinding cannot find a row in the list that is suitable for all bindings". If I move the DataSource assignment into the form's constructor, I don't get the error.
If I remove the data binding for the DateTimePicker, it works fine.
Can anyone explain what the problem is ?
public partial class Form1 : Form
{
private BindingSource bs;
public Form1()
{
InitializeComponent();
button1.Click += new EventHandler(button1_Click);
bs = new BindingSource();
bs.DataSource = typeof(Thing);
this.textBox1.DataBindings.Add("Text", bs, "MyString");
this.dateTimePicker1.DataBindings.Add(new Binding("Value", bs, "MyDate"));
//Thing thing = new Thing { MyString = "Hello", MyNumber = 123, MyDate = DateTime.Parse("01-Jan-1970") };
//bs.DataSource = thing;
}
private void button1_Click(object sender, EventArgs e)
{
Thing thing = new Thing { MyString = "Hello", MyNumber = 123, MyDate = DateTime.Parse("01-Jan-1970") };
bs.DataSource = thing;
}
}
public partial class Thing
{
public String MyString { get; set; }
public Int32 MyNumber { get; set; }
public DateTime MyDate { get; set; }
}
}
Thanks
Edit:
It seems that if I change the data binding for the DateTimePicker control such that I bind to the "Text" property, the problem goes away. I don't understand why that would be though, because "Value" is valid for data binding.

Insert The Value from 10 radio button list from .aspx page(asp.net) into a single row into the data base

I have 10 radio button list in the .aspx page (in asp.net) ,in the database one Row (name Answer)
1.In the Model Layer ,I mention this code
public class DimensionQuestion
{
public string NewCompanyName { get; set; }
public string NewSurveyName { get; set; }
public List<int> NewAnswer { get; set; }
}
2.In the Data Layer Layer,I mention this Code,
public static bool InsertNewDimAnswer(DimensionQuestion dimension)
{
bool result;
using (var helper = new DbHelper())
{
_cmdtext = "sp_InsertNewDimAnswer";
var success = new SqlParameter("#Success", SqlDbType.Bit, 1, ParameterDirection.Output, true, 0, 0,
"Result", DataRowVersion.Default, 0);
foreach (string s in dimension.NewAnswer)
{
if (s.Trim().Length > 0)
{
var parameter = new[]
{
new SqlParameter("#CompanyName", dimension.NewCompanyName),
new SqlParameter("#SurveyName", dimension.NewSurveyName),
new SqlParameter("#Answer",s ),
success,
};
helper.ExecuteScalar(_cmdtext, CommandType.StoredProcedure, parameter);
}
}
result = (bool)success.Value;
}
return result;
}
Finally in the Business Layer
private void FillObjects()
{
List Answer = new List();
Answer.Add(Convert.ToInt32(rbAnswer1.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer2.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer3.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer4.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer5.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer6.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer7.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer8.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer9.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer10.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer11.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer12.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer13.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer14.Text.Trim()));
Answer.Add(Convert.ToInt32(rbAnswer15.Text.Trim()));
_DimensionQuestion.NewAnswer = Answer;
}
And on the Button Click
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
FillObjects();
if (InsertData.InsertNewDimAnswer(_DimensionQuestion)
{
ShowMessage("Information is saved");
Reset();
}
else
{
ShowMessage("Please try again");
}
}
finally
{
//_DimensionQuestion = null;
}
}
Just store it as a semi colon delimited string in the database.
When building the string loop through the radio buttons and then add ; then store the full string in the database.
Then when filling the data back in just split the string by the ; and fill the array/list with each item.

DevExpress LookUpEdit SelectedText Problem

I have some lookupedits binded to some lists where the user can choose values and then save in database. I use EditValueChanged events to handle the values. So far all good!
Now i need to grab the values from the database and assign them to the lookupedits. I don't use BindingSource for the whole object cause lookupedits are binded to independent lists.
As i supposed and read from the documentation, SelectedText is what i need, but when I'm assigning the string i want, it just don't work and sets an empty string. Same Behavior for the DateEdit control, I'm assigning a DateTime value and seems to have this value but doesn't shows it. I could set the EditValue property but i get nothing showed up in the LookUpEdit again.
How to force the LookUpEdit to show me the value i want, basically go to the row with the value i set and show the text in the editor too, or set the SelectedText and match it with its list and show it!
I guess this should be easier...Any help appreciated!
Example:
myLookUpEdit.SelectedText = "George" // The LookUpEdit is Binded to a List<Names> and has the name George.
Thank you
Whenever I am setting the value of a LookupEdit I use EditValue.
You need to make sure that you set the ValueMember property of the LookupEdit to whatever you want to appear in EditValue. DisplayMember will what is displayed when the LoodupEdit is closed. You can pass in a string to the name of the property you want in your object to these properties.
Setting the SelectedText value has the same effect as typing into the control as far as I am aware.
public partial class Form1 : Form
{
List<Name> MyNames = new List<Name>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MyNames.Add(new Name("John", "Smith"));
MyNames.Add(new Name("John", "Doe"));
MyNames.Add(new Name("Jane", "Doe"));
MyNames.Add(new Name("Jane", "Smith"));
lookUpEdit1.Properties.DataSource = MyNames;
lookUpEdit1.Properties.DisplayMember = "FirstName";
lookUpEdit1.Properties.ValueMember = "FirstName";
}
private void lookUpEdit1_EditValueChanged(object sender, EventArgs e)
{
string mystring = lookUpEdit1.EditValue.ToString();
lookUpEdit1.EditValue = mystring;
}
}
public class Name
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Name(string firstName, string lastName)
{
this.FirstName = firstName;
this.LastName = lastName;
}
}

Resources