Flex - combobox data - apache-flex

I'd like to create a combobox which will get users from an arrayList & another field for creating a new user.
for example when i open the combobox i'd like to see the rows :
Create new user
User A
User B
where the users come form an arrayList and the "create new user" option is always there.
How can I do it?
P.S
I don't wan't to add "create new user" obj to the arryList - so this is not a desired solution.
Thanks for your help,
Dan

Just create an intermediate ArrayList, add the "create new user" option to it, copy all the elements from the other ArrayList, and finally assign it to the combobox:
var cbArray = new ArrayList();
cbArray.push("Create new user ");
for (int i = 0; i < yourArrayList.lenght; i++) {
cbArray.push(yourArrayList[i]);
}
// Then assign cbArray to the combo box

Related

javafx combobox of object how to get selection

I have a comboBox i have populated using student from an arraylist:
ComboBox<Student> comboBox = new ComboBox();
for (int i = 0; i < control.getSize(); i++) {
comboBox.getItems().add(control.returnElement(i));
How do I now on a Button press know which Student object the user has selected so I can pass it into a method, I might be able to work with just knowing the index too
I tried it like this but it gives me an error:
Student studentSelect = comboBox.getItems();
with comboBox.getValue(); or comboBox.getSelectionModel().getSelectedItem();

Xamarin Forms Picker SelectedItem to existing SQLite table

I am fairly new to this, and am having some issues trying to set a Picker SelectedItem to an existing SQLite table.
I have managed to populate the picker (and tables) with no issues. Now I need to Updated (or Insert) the existing cell value with the SelectedItem.
I can set the SelectedItem value, but when trying to insert it into an existing table I am having issues.
I did find one way to get it set, but doing so creates a new table each time (with the SelectedItem correctly displaying).
Is there something I am missing to get the SelectedItem into an existing table, without having to create a new table each time?
Thanks!
Xaml.cs
void TermGoClicked(object sender, EventArgs e)
{
//local database where populated table is stored
using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
{
//sets the Picker SelectedItem index
var pickerItem = termPicker.Items[termPicker.SelectedIndex];
//created new Courses table
var courses = new Courses();
//sets the PickerItem column with the Selected Item on newly created table.
courses.PickerItem = pickerItem;
conn.Update(courses);
Navigation.PushAsync(new TermPage());
}
}
Xaml
<Picker x:Name="termPicker"
ItemsSource="{Binding terms}"
ItemDisplayBinding="{Binding TermName}"
Title="Select a term"
IsEnabled="True"/>
I got it!
I had tried to access the existing Courses table using
var courses = conn.Table<Courses>;
but it wouldn't find the PickerItem column. So I had removed it. However, I added
var courses = conn.Table<Courses>.FirstOrDefault();
And it worked perfectly!
Thanks #Jason for pointing me in the right direction!

Want To Copy Certain Fields From Previous Entry To New Fragment

Short Version: I want to have my Copy button in a table to be able to grab the values from an existing entry and populate those into a "Create Entry" Page Fragment. This way users don't have to reenter all the data when making a new entry.
Long Version:
I have two buttons added the rows in my table: Edit and Copy.
The Edit Button uses the following code to grab the information from that specific row and uses the Fragment to edit the entry.
widget.datasource.saveChanges();
app.datasources.SystemOrders.selectKey(widget.datasource.item._key);
app.showDialog(app.pageFragments.SystemOrders_Edit);
The Copy button is currently using the following code to duplicate the entry and automatically create it.
//Allows for copying table/row
var rowDataSource = widget.datasource;
var listDatasource = app.datasources.SystemOrders_HideComplete;
var createDataSource = listDatasource.modes.create;
widget.datasource.saveChanges();
// Enter fields you want to duplicate below
createDataSource.item.ProjectName = rowDataSource.item.ShowName;
createDataSource.item.DeliveryInfo = rowDataSource.item.DeliveryInfo;
createDataSource.item.SOB = rowDataSource.item.SOB;
createDataSource.item.DeliveryDate = rowDataSource.item.DeliveryDate;
createDataSource.item.Company = rowDataSource.item.Company;
createDataSource.item.Location = rowDataSource.item.Location;
createDataSource.item.AdditionalPeripherals = rowDataSource.item.AdditionalPeripherals;
createDataSource.item.Notes = rowDataSource.item.Notes;
createDataSource.createItem();
I would like to change this behavior so that the Copy button grab the values from those specific fields, however instead of doing a createDataSource/createItem(); I want it to place those values into a Page Fragment (ex: SystemOrders_Add) that has the corresponding fields.
This way the user can click "Copy" and the SystemOrders_Add Fragment appears with pre-populated values.
I want to make sure these values are only in the Page Fragment and do not get commited until the user presses the Submit button.
newSOEmailMessage(widget);
widget.datasource.createItem();
app.closeDialog();
Thank you for your help!
one way you can accomplish this is by passing the data to Custom Properties defined in your Page Fragment and then you can place those properties to the corresponding fields. I recommend you also check this article https://developers.google.com/appmaker/ui/viewfragments#use_custom_properties_to_customize_page_fragments
First you need to create the Custom Properties inside your Page Fragment. Then in your Copy button onClick event you can use something like this to save the row data from your table to the Custom Properties:
var rowDataSource = widget.datasource.item._key;
app.datasources.SystemOrders.selectKey(rowDataSource);
var projectName = app.datasources.SystemOrders.item.project_name;
var deliveryInfo = app.datasources.SystemOrders.item.delivery_info;
//...
app.pageFragments.SystemOrders_Edit.properties.ProjectName = projectName;
app.pageFragments.SystemOrders_Edit.properties.DeliveryInfo = deliveryInfo;
//...
app.showDialog(app.pageFragments.SystemOrders_Edit);
Assuming you have a form inside your Page Fragment, you can bind the value of each field with custom properties. Binding will ensure that the data is pre-populated. This can be done for each field via the Property Editor and the binding should look like this: #properties.ProjectName
Inside your Submit button onClick event you can use something like this to create a new item in the datasource using the values available in each field.
var projectName = widget.root.descendants.Field1.value;
var deliveryInfo = widget.root.descendants.Field2.value;
//...
var myDatasource = app.datasources.SystemOrders_HideComplete;
var myCreateDatasource = myDatasource.modes.create;
var draft = myDatasource.modes.create.item;
draft.project_name = projectName;
draft.delivery_info = deliveryInfo;
//...
// Create the new item
myCreateDatasource.createItem();
app.closeDialog();
You can set properties back to null once item is created (maybe onDetach) like this:
app.pageFragments.SystemOrders_Edit.properties.ProjectName = null;
Hope this helps!
I have a feeling that removing this line from the Copy Button click handler will make a trick(of course, if your page fragment is bound to ds.modes.create.item):
createDataSource.createItem();
In case, you are using Manual save mode and you are trying to reuse Page Fragment without overriding datasource... you need create new items using different approach:
// Copy Button click handler
var source = widget.datasource.item;
var listDatasource = app.datasources.SystemOrders_HideComplete;
// This line will add new item to the list datasource
// without saving it to database.
listDatasource.createItem();
var target = listDatasource.item;
// Enter fields you want to duplicate below
target.Field1 = source.Field1;
target.Field2 = source.Field1;
...
// Show fragment (assuming it is bound to listDatasource.item)
app.showDialog(app.pageFragments.EditItemFragment);
// -----------
// Page Fragment's Submit Button click handler
...
listDatasource.saveChanges(function() {
// TODO: handle successful save
});
Thank you to Pavel and Wilmar. The solution that worked for me is listed below:
//Allows for copying table/row
var rowDataSource = widget.datasource;
var listDatasource = app.datasources.SystemOrders_HideComplete;
var createDataSource = listDatasource.modes.create;
widget.datasource.saveChanges();
// Enter fields you want to duplicate below
createDataSource.item.ShowName = rowDataSource.item.ShowName;
createDataSource.item.DeliveryInfo = rowDataSource.item.DeliveryInfo;
createDataSource.item.SOB = rowDataSource.item.SOB;
createDataSource.item.Notes = rowDataSource.item.Notes;
app.datasources.SystemOrders.selectKey(widget.datasource.item._key);
app.showDialog(app.pageFragments.SystemOrders_Add);

Using Auto Increment ID with ASP.NET checkbox list

First and foremost, I'm pretty new to programming, so attention to detail is appreciated.
I've currently got an asp checkbox list that receives data from an SQL table. I'm encountering a problem where if there's 2 items that are exactly the same, my remove function will remove both items. The following is the code for that:
protected void btn_remove_Click(object sender, EventArgs e)
{
for (int i = 0; i < UPCList.Items.Count; i++)
{
if (UPCList.Items[i].Selected)
{
var item = UPCList.Items[i];
var frcID = item.Value;
_itemNumberRepository.Delete(frcID);
}
}
Response.Redirect("WebForm2.aspx");
Response.End();
}
public string Delete(string itemCode)
{
string connectionString = foobar
Int32 returnDeleted = 0;
string deleteUpcCode =
"DELETE FROM compare1 "
+ string.Format("WHERE itemcode = '{0}'",itemCode);
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(deleteUpcCode, connection);
command.Connection.Open();
returnDeleted = command.ExecuteNonQuery();
command.Connection.Close();
}
return returnDeleted.ToString();
}
I've been told to use Auto Incrementing ID from SQL so that each row will have a unique ID so I can delete only the selected lines. However, I don't even have a clue how to do that. I've already turned on the identity option in SQL for the itemcode column, but aside from that, I'm lost. How do I go about using that ID to delete only selected items from the checkbox list in asp?
When you say the items are "exactly the same", do you mean that they have the same item code? And item codes are allowed to be duplicated in your system (i.e. is that the correct business rule)?
If so, that's why you need a auto-generated ID for each line, so that each row is unique. Which means that you need to use that ID in your DELETE query instead of the item code.
Typically, in a (ASP.NET) web app, this sort of thing is done with a "grid". You can use a GridView with two columns: one is a checkbox and another column is just a label showing the item code. Each row is bound to the ID field.
So, I recommend that you start by checking out GridView (there's lots of examples out there on the web): MSDN documentation for GridView

how to set list of data into session context?

I want to store list of data into session object. My scenario is I have one gridview control inside a page. below of the gridview have two text boxes and button. When i press button than gridview will have filled with text boxes value. Every time my pressing on button it will add new row into gridview to show entered data..So, for that i have to use session context. But my issue is how to store two textboxes value into session and how to read it again..
I dont want to use temporary sql database table.
So if anyone knows about it than please help me..
Thanks in advance.
Try this :Use this code on the click event of button
if(Session["value1"] == null)
{
Session["value1"] = new List<String>();
}
((List<String>)Session["value1"]).Add(testbox1.value);
To output the data you can loop through all the values :
List<String> V = (List<String>) Session["value1"];
for(int j = 0 ; j < V.Count ; j++)
{
String str = V[j];
//ADD str TO GRID VIEW.....
}
The same code goes for textbox2.

Resources