I have two list that I load when my app starts. The first one loads a complete set of data from the database, the second one independently loads a set of associated data from file.
Each list is loaded into a BindingSource and set as the DataSource for their respective combobox. The data is loading just fine.
The issue is that I need to have the second comboBox only display the elements of its list that correspond with the selected value of the first list.
I have attempted to set the value members to the referential bit of data, but cant figure out how to get the comboBoxSettings to only show the the items whose EventID matches the selected item's EventID from the EventList comboBox.
//Event List comboBox
comboBoxEventList.DataSource = _eventSimPresenter.BindingSourceEventList;
comboBoxEventList.DisplayMember = "DisplayName";
comboBoxSettings.ValueMember = "EventID";
//Settings combobox
comboBoxSettings.DataSource = _eventSimPresenter.BindingSourceUserSettings;
if (_eventSimPresenter.BindingSourceUserSettings.Count > 0)
{
comboBoxSettings.DisplayMember = "EventName";
comboBoxSettings.ValueMember = "EventID";
}
thanks!
You can reate a method in _eventSimPresenter that return a BindingSourceUserSettings by eventId. When the 1st comboBox changes, take the selected eventId and update 2nd comboBox datasource:
...
comboBoxSettings.DataSource =
_eventSimPresenter.GetBindingSourceUserSettings(selectedEventId)
if (_eventSimPresenter.BindingSourceUserSettings.Count > 0)
{
comboBoxSettings.DisplayMember = "EventName";
comboBoxSettings.ValueMember = "EventID";
}
In other terms, the filtering should be applied to the datasource since it's not possible to do it via the comboBox.
Related
My Problem:
This is my form
I would like to just filter out same ID rows
Barely any code to show pretty much dragged and dropped entity-es and did some customizing.
Toolstrip and datagrid are binded to same source
My Goal:
I would like my form to filter out only the rows with same ID as ID in textbox when I navigate with toolbox buttons
My thoughts so far: Perhaps I can make a query where ID in textbox matches ID in first column and weed out those rows and just display them. But how would that keep the format I have? Comboboxes etc.. some columns have different binding sources, for example column #2, column#3 are have different binding sources as opposed to column#1(to which i'm trying to filter rows) and column#4,5
Edit: I have tried following
nastavniPlanProgramDataGridView.CurrentCell = null;
foreach (DataGridViewRow row in nastavniPlanProgramDataGridView.Rows)
{
if(row.Index!=rowIndex)
{
row.Selected = false;
row.Visible = false;
}
else
{
if(row.Index==rowIndex)
{
row.Selected = true;
row.Visible = true;
}
}
However i keep encountering an error when executing row.Visible=false;
Solved by simply adding the following before executing the above code-snippet in the question.
AllowUserToAddRows = false;
I am working on WPF Datagrid where we are customizing the grid to support functionalities like search, filter, column Hiding/Un-Hiding etc,
For Filter and Search we are using CollectionViewSource to get the ICollectionView and on that list we are performing various operations mentioned above.
For a particular Functionality like search, User had reordered the columns and then performed search operation, i am getting the ICollectionView data using the below function:
ICollectionView objDatacollectionview =
CollectionViewSource.GetDefaultView(DataSource.DataGridSrcCollection);
DataSource.DataGridSrcCollection is my ObservableCollection<DataRowView>.
From the objDataCollectionView object, I get the itemArray of each row and search for the text and start highlighting the cell where the text is found, but the problem I am facing is my CollectionViewSource object always returns the DataRow ItemArray in the original order when the Grid is loaded, as it is not considering the Column Reordering, the search is not pointing to the first column, it is actually pointing to the column which was the first column when loaded for the first match text.
The question I had is , is there a way to get the item array value in the correct order on how the columns are re-ordered, if not can I use any other approach with Collectionview so that I can highlight the correct item when search is done.
Below is the sample code i had
below is the sample code
objDatacollectionview = CollectionViewSource.GetDefaultView(DataSource.DataGridSrcCollection)
// Initially get all the DataRowview ItemArray , Here i get all the rows itemarray text as it is
var temp = (from s in objDatacollectionview.OfType<DataRowView>()
select s.Row.ItemArray).ToList();
for (int i = 0; i < temp.Count(); i++)
{
// Now in each item array , i search for the string and will get the list of the strings that match the searchText
var cellitems = temp[i].Where(x => x.ToString().Contains(searchText, StringComparison.OrdinalIgnoreCase)).
Select(x => x).ToList();
//This is to point to the row where there is first occurance of the searched text.This will execute only for the first time
if (cellitems.Count() != 0 && !IsfirstSelectedRowIndex)
{
DataRowView dv = objDatacollectionview.OfType<DataRowView>().ElementAt(i);
objDatacollectionview.MoveCurrentTo(dv);
int cellIndex = temp[i].Select((Value, Index) => new { Value, Index }).Single(p => p.Value.Equals(cellitems[0])).Index;
DataGridCellInfo cellinfo = new DataGridCellInfo(cellitems[0], batchDataGrid.Columns[cellIndex]);
batchDataGrid.CurrentCell = cellinfo;
IsfirstSelectedRowIndex = true;
}
} `
In the above code as i am moving through each row itemArray data i have is the original order, not the re-ordered columns, i can use the index to column mapping, but after this operation i have to support previous search item and next search item, so i am thinking that would impact the performance if i am doing search with column display index every time.
Each DataGridColumn has a DisplayIndex property, which will tell you the current position of the column. This will allow you to determine the ordering.
I've set up a product which uses a custom line item type called "Custom Notes" (created through the UI at Configuration > Line Item Types). One of the fields in "Custom Notes", that is exposed at checkout, is a "field_notes" textarea field. It works as intended... in a product display I can add some custom text, click ORDER and the note carries through to checkout.
However, I need to create these orders programmatically. I've gotten to the point where i'm using a hook_menu to submit an order and it works great. The only problem is that I can't seem to set the value for the "field_notes".
// Load whatever product represents the item the customer will be
// paying for and create a line item for it.
$line_item = commerce_product_line_item_new($product, $quantity, $order->order_id);
// Save the line item to get its ID.
commerce_line_item_save($line_item);
//***this is the part that's not working. trying to set the field_notes field***
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
$line_item_wrapper->field_notes->set("Does this work??");
// Save the line item to get its ID.
commerce_line_item_save($line_item);
// Add the line item to the order using fago's rockin' wrapper.
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_wrapper->commerce_line_items[] = $line_item;
// Save the order again to update its line item reference field.
commerce_order_save($order);
What am i doing wrong? Thanks!
I think it could be because you are not passing the correct line item type to commerce_product_line_item_new. For example, this is how I would do it:
$line_item = commerce_product_line_item_new(
$product,
$quantity = 1,
$order_id = 0,
$data = array(),
$line_item_type = 'my_custom_line_item_type'
);
In my application I hava combobox which is holding some values from databse ( some real time updated list ). This ComboBox list is updated every 1 minute.
List dosen't have null values. When I'm setting this list to ComboBox..
ComboBox box = new ComboBox(items);
.. there is one extra "empty" row, which is perfectly fine because non value is selected.
Right after I'm selecting some value my "empty" value disappears from the list.
My main question is How to keep this value on the list?
Why this is a problem..
Scenerio values is selected in database, first application start
List is loaded ( wiht selected empty value ).
Value is selected.
During first background refresh, empty values disappears, and combobox value is selected to n+1, next value is selected.
If I want to select empty values I have to all clearSelection from selection model / by some extra control.
While it is an old question, I spent quite bit of time trying to solve the same issue in my application and thought i might as well add my solution here.
One possible workaround is to create an extra list that contains null and the items you wish to be selectable.
ObservableList<String> selectableActivities = FXCollections.observableArrayList("a", "b", "c");
ObservableList<String> selectableActivitiesWithNull = FXCollections.observableArrayList();;
selectableActivitiesWithNull.add(null);
selectableActivitiesWithNull.addAll(selectableActivities);
In order to support updates of the original list you would need a ListChangeListener that updates the extra list according to changes in the original list.
selectableActivities.addListener((ListChangeListener<String>)(change -> {
while (change.next()) {
if (change.wasPermutated()) {
selectableActivitiesWithNull.sort((a, b) -> {
return Integer.compare(selectableActivities.indexOf(a), selectableActivities.indexOf(b));
});
} else if (change.wasRemoved()) {
selectableActivitiesWithNull.remove(change.getFrom()+1, change.getTo()+2);
} else if (change.wasAdded()) {
selectableActivitiesWithNull.addAll(change.getFrom()+1, selectableActivities.subList(change.getFrom(), change.getTo()));
} else if (change.wasUpdated()) {
for (int i = change.getFrom(); i < change.getTo(); ++i) {
selectableActivitiesWithNull.set(i+1, selectableActivities.get(i));
}
}
}
}));
And finally you use the extra list for the ComboBox items.
ComboBox<String> combobox = new ComboBox<String>();
combobox.setItems(selectableActivitiesWithNull);
Now you can modify the original list as usual and the ComboBox will update accordingly while also having an empty selection as the first item. And most importantly your original list will not be polluted by placeholder objects that could cause issues in other parts of the application.
This will also work with other objects, assuming that you add an apropriate StringConverter to the ComboBox. Note that the converter must also be able to handle null values if using the above approach.
StringConverter<Object> activityConverter = new StringConverter<Object>() {
#Override
public String toString(Object object) {
return object != null ? object.toString() : "";
}
#Override
public ActivityDataRow fromString(String string) {
return null;
}
};
combobox.setConverter(activityConverter);
While this approach is not exactly what you desired, I believe this is a close you can get without implementing a custom combobox.
In ext js, when I have a combo, there is display value and value( which is sent to server). I do not need displayValue to send to server, but I need to capture it on the page and display an alert.
What is the eextjs method of doing this?
combo.getValue() will return the underlying value...and I do not see any combo.getDisplay()
EDIT: Just to clarify, I am looking to get the display value of the item that is selected by the user. I wish to show an alert on the onselect or on changeevent.
If you set the valueField property on the combo box to the value you wish to display in the alert that will work fine.
alert(combo.getValue());
If you want this value to be different from the value you submit to the server you will have to get the store from the combo box and find the corresponding record.
var store = combo.getStore();
var index = store.find('*YourFieldName*', combo.getValue());
if(index != -1)//the record has been found
{
var record = store.getAt(index);
//you can then do what you like with the record.
}
combo.getStore().getById(combo.getValue()).raw.displayAttribute //Ext 4.x,
//displayAttribute: displayField or displayed attrib in store data for the combo
We can retreive the underlying store, then use our value as a key to get the display value.
Something like this (I haven't tested it):
var displayValue = combo.getStore()[combo.getValue()]
We can get the combo box display value something like this...
getRawValue( ) : String
Returns the raw String value of the combo, without performing any normalization, conversion, or validation. Gets the current value of the input element if the field has been rendered, ignoring the value if it is the emptyText.
combo.getRawValue();
Let's assume that you have following in your combobox:
id: 'COMBOBOX_ID',
displayField: 'COMBOBOX_DIS_FIELD_NAME',
valueField: 'COMBOBOX_VAL_FIELD_NAME'
Then, you can do following:
var combo = Ext.getCmp('COMBOBOX_ID');
var comboStore = combo.getStore();
var index = comboStore.find('COMBOBOX_VAL_FIELD_NAME', combo.getValue());
if(index != -1)
{
var selectedItemDisplayValue = combo.getStore().getAt(index).get('COMBOBOX_DIS_FIELD_NAME');
}