Displaying List<string> in a grid column - devexpress

Is there a way that one can use a control in a gridview that displays a simple List<string> in a dropdown just like SearchLookUp or even a simple Dropdown? The tricky part is that this List<string> is not predefined, it can change for each row in the grid.
For example if I have a grid with each row representing an ECU of a vehicle. This object contains a List<string> representing SoftwareVersion allowed for the ECU, among st which the user can then select one that is in accordance to their needs. Since each ECU can have different software versions, I cannot assign a pre-defined data source and bind it to SearchLookUpEdit . So I am searching for a solution to make it happen.
Any suggestions will be highly appreciated.

You can use a RepositoryItemComboBox control for this. In order to have a different list of ECU items in each row, handle the GridView's CustomRowCellEdit event and assign the editor at runtime.
You can add all of the strings in your List to the editor's Items collection and additionally set the TextEditStyle property to TextEditStyles.DisableTextEditor to prevent the end-user from typing in their own values.

Related

Filter and Bind a Multiselect

I am trying to implement a Many-to-Many relation between a class and its students in a form.
The form can be used to create or edit a class. Also students can be added to that class. To reduce the effort needed to enter students, I would like to add a multi-select that shows the entries from the students-table. But since the number of students is expected to be large, I would like to filter this multi-select.
I checked this question on filtering lists and the sample app "Project List. I understand that the standard workflow with a table would be to bind the value of a search box to the #datasources.STUDENTS.query.filters.email._contains and set the tables datasource property to STUDENTS
But, as I understand it, a multi-select element's value property must be bound to #datasource.item.students and its datasource property must be CLASS in order for the auto-saving to work.
Hence I wonder whether it is possible to filter a multi-select element.
I don't see the problem, but I think I see a misunderstanding.
You said: "I understand that the standard workflow with a table would be to bind the value of a search box to the #datasources.STUDENTS.query.filters.email._contains"
You need to bind the OPTIONS (not value) to the datasource query, as it is the options that will draw its records from the #datasources.Students.query datasource.
You can then set the VALUE of the multi-select widget to #datasource.item.students (where you want selected values from the student query options to be saved).
You will also need to set the NAMES property (since the options are likely student records). Names will be the Student datasource projection of whatever string field you want to appear in the options list.

AdvancedDataGrid (grouping) quick jump to row

I have a problem with the AdvancedDataGrid widget. When the dataProvider is an ArrayCollection (of arrays), the nth array (within the collection) is also the nth row within the grid, and I can jump and display the i-th row by scripting
adg.selectedIndex = i;
adg.scrollToIndex(i);
now, when I add a Grouping, the dataProvider ends up being a GroupingCollection2, and now the index in the dataprovider's source does not correspond to the index in the adg anymore (which is understandable, because it's being grouped).
How can I select and display a row in grouped data efficiently? Currently, I have to traverse the adg and compare each found item with its data attributes in order to find the correct index of the row within the adg, and jump to it like above. This process is very slow. Any thoughts?
edited later:
We already used a caching object as Shaun suggests, but it still didn't compensate for the search times. In order to fully construct a sorting of a list of things (which this problem equates to, as the list is completely reordered by the grouping), you always have to know the entire set. In the end we didn't solve that problem. The project is over now. I will accept Shaun's answer if no one knows a better way in three days.
Depending on what values your comparing against you can store the objects in a dictionary with the lookup using the property/properties that would be searched for, this way you have a constant time look-up for the object (no need to look at every single item). Say for example your using a property called id on an object then you can create an AS object like
var idLookup:Object = {};
for(myObject in objects)
idLookup[myObject.id] = myObject;
//Say you want multiple properties
//idLookup[myObject.id]={};
//idLookup[myObject.id][myObject.otherProp] = myObject;
now say the user types in an id you go into the idLookup object at that id property and retrieve the object:
var myObject:Object = idLookup[userInput.text];
myAdg.expandItem(myObject, true);
now when you want to get an object by id you can just do
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/AdvancedDataGrid.html#expandItem()
I haven't done any thorough testing of this directly, but use a similar concept for doing quick look-ups for advanced filtering. Let me know if this helps at all or is going in the wrong direction. Also if you could clarify a bit more in terms of what types/number of values you need to lookup and if there's the possibility for multiple matches etc. I may be able to provide a better answer.
Good luck,
Shaun

How to determine currently sorted header column in data grid?

I want to know which header the user clicked on to give the currently sorted view.
Is there an API in flex framework that I can use to achieve this? Hopefully I can get back a column index so I know how it is currently sorted.
Thanks,
Mike
The mx.controls.DataGrid has a property named columns. Each column in this collection is an object of type mx.controls.dataGridClasses.DataGridColumn with a boolean property named sortDescending.
Otherwise, you can receive and handle the DataGrid event headerRelease. This event is transmitted when the user releases the mouse button on a column header, causing the column to become sorted.

How can one extract/convert information from a Listview (to a DataTable)?

I have a relatively simple Listview that suddenly needs (due to new requirements) to have it's 'layout' extracted to a DataTable so that a common routine can convert it to an Excel spreadsheet for export purposes.
The ItemTemplate is just a series of Table Rows with some text, data-bound labels and textboxes with validators in the cells.
Usually, when trying to pull out a particular value (like what was entered into a text box), I use the ListViewItem's .FindControl method.
For Each objItem As ListViewItem In lvwOptions.Items
Dim objTextHrsLabor As TextBox = CType(objItem.FindControl("txtHrsOptByLabor"), TextBox)
decHours = CDec(objTextHrsLabor.Text)
Next
In this case, however, I'm trying to take all the data displayed - all the 'rows and columns' of the table that was created.
Inside the ForEach / Next loop of ListViewItems, I started a ForEach/Next loop of Controls for each instance's controls but I got some really strange results returned (like controls that had a couple of table cells in them).
I get the sense I'm headed in the wrong direction. All I want is for the nicely-formatted 5-line, 6 column table to be converted to a 5-line, 6-column data table.
Is there another avenue I should be looking at?
I would look at the underlying data source for your ListView.
The data source must be a collection or an IEnumerable and you should be able to iterate through it to build your data table.
If you know that all elements are of the same type then you can use the first element and look at its properties using reflection to determine which columns your table should contain. Then you can add DataRows to your table and fill in the columns using the property names.
This will probably be faster than iterating through the generated html of the ListView.
I used this approach for exporting a ListView to Excel: http://aspalliance.com/771_CodeSnip_Exporting_GridView_to_Excel.
I know it deals with a GridView, but I adapted it to a ListView (as long as the underlying structure is a table) and it worked fine for me.
HTH.
you can use..
listView1.Items[0].SubItems[0].Text
this will be helpful , really simple and easy . You can extract info right on the basis of index & use anyway you want.

Get Changed Rows of GridView ASP.Net

How Can I find all the rows that has been changed in gridview. I can not use Ajax in any form
First get the contents of your grid before it was changed (such as caching the results of the original gridview datasource binding). Then go through the dataset/datatable/however you want to store it, and compare the contents with the current rows of the gridview.
There's no real efficient way to do this, no method like GridView.GetAllChangedRows(). So, what you might do instead is keep a behind the scenes List that you add to each time a row is modified (use the RowUpdated method), then clear this list when needed.
It depends upon how many columns you want to edit in a row.
If you have only one editable column in a row then you can associate a javascript method with that control which you want to modify and in that method you can get a rowid which you can save in another hidden field and in server side you can get all rows whose ids are stored in hidden field.
If you have whole row editable in that case the best approach I think you should save the original data source somewhere and also set a javascript method with rowclick event to get rowid which user selects. Then when user clicks on submit button get all rows whose row ids are stored in hidden field then compare those with same rowid in datasource. This is the best approach from my point of you.
Let me give you an example, suppose there are 1000 rows in a grid and user clicks on only 180 rows. In that case we will compare only 180 rows and wont compare rest of the rows.
Please let me know if somebody has better idea then this.

Resources