I have a scenario which is as follows:-
A form containing 2 grids. The grid on the left contains a list of groups. When a group is selected the grid on the right populates with another list with check boxes.
I would like to be able to select group A and select some random check boxes and then switch to group B and select some other check boxes. However when I select group A again I would like to be able to restore the previously selected check boxes.
This would allow me to preload the settings from the database and also update the changes in one go rather than expecting the user to select apply after the changes for each group.
I'm unsure of the best way to approach this problem. Any feedback is appreciated.
Thanks
Sean.
I've done something like this using DataTables and DataViews to implement client-side filtering.
You have a dataTable with the tickboxes that contains all groups of data.
Then when you click grid 1, you update the DataSOurce of the grid to a new DataView(DataTable,"GroupID=1")
,"",CurrentRows) (i.e. Sets the filter proprety of the DataView to filter on the selected group
THen when you're done, the DataTable has all the tick boxes you just saev the DataTable to the database.
Hope that makes sense.
I'd start with coming up with a database table to store your data - let's say MyTable(UserId, GroupId, ItemId, Selected). When the app starts I'd read the data from the table based on the UserId. I'd process this data into a couple of collections that I could associated with the grids - one having unique groups, the other items associated with a group and the selection status. Set up some event handlers to keep the collections in sync with the user input. Implement some save routine upon hitting a button or form closing and you should be good !
Related
The title might be slightly misleading, but I can't quite think how to describe this better in just a few words unfortunately, so apologies if it's not fitting.
Anyway, I am querying a SQL table containing orders placed.
I store all orders queried results in a List and to display to the user I tranform it into a DataTable and use it as the DataSource of a DataGridView, which works just fine. Effectively this first DataGridView can be considered to contain all orders.
I then have a second DataGridView which contains orders that belong to the employee running the application. Again there's a List in the back end and a DataGridView to display this to the user.
Now I'd like to allow the user to bring orders that would not normally be in his personal DataGridView into it. The idea is the user selects orders (rows) from the "all orders" DataGridView and when he clicks a button those get added to the "users orders" DataGridView.
However, because in the back end there is a List (and the DataGridView contains a DataSource so I can't just add rows to it), I can't add directly from one DataGridView to the other.
I have the following working code, but I think it can be simplified and am just after some suggestions:
foreach (var row in dgvAllTenants.SelectedRows.Cast<DataGridViewRow>().Where(row => _myTenants.Count(x => x.TenantId.ToString() == row.Cells["TenantId"].Value.ToString()) == 0))
{
_myTenants.Add(_allTenants.Where(x => x.TenantId.ToString() == row.Cells["TenantID"].Value.ToString()).ToList()[0]);
}
dgvMyTenants.DataSource = _myTenants.ToDataTable();
I have a DataGridView with several TextBoxColumns and one ComboBox column called 'combo' that holds the client type. The problem is that I'd like to show both the currently selected client-type value along with the dropdown client-type list to validate future changes by the user. In SQL Server, I have a DB with two table columns, 'client_type_dropdown.name' and 'clients.client_type'. The 'client_type_dropdown.name' column is a validation list. The 'clients.client_type' column contains the current client type for clients in the database. Is there a way to show in 'combo' both 'client_type_dropdown.name' and 'clients.client_type' , i.e., one source for the ComboBoxColumn dropdown and a different source for the textbox part of 'combo'? Or do I need to have two columns in my grid?
I appreciate your help.
I'm using a third party grid, but I usually handle this by setting the combo drop down style to DropDown instead of DropDownList. This will allow your original database value to display, even if it isn't in the list.
This also allows free typing of values into the combo field, so the trick after that is to validate the user input to make sure it matches a value in the list before you allow them to save updated values. You could play around with the LimitToList property of the combo to possibly save you doing the validation manually, but with most controls I have worked with it will give you more grief than help.
I have two tables, Customer and Address. One customer can have one or more addresses.
My view is a ListDetail with all my customers on the left as a list and the edition on the right.
Under the edition I have the "address area" with a list of addresses and an edition on the selected.
My problem is all my addresses are listed. I just want addresses with the matching customerId (selected on the first list).
Here is a drawing to help you see what I am talking about:
I can create a button on the first list that show a popup with the selected Id but I don't know how to put a parameter on my address collection.
Please tell me if you need more details.
Edit : A good example of what I want is the 'Roles' view created by default. I haven't found how to edit this view to see how it works but if you select a 'role' the list of users is updated to show only those that have this role.
If your two tables are related (meaning you've created a relationship between them in the table designer), then what you describe should happen automatically. Using the Add Screen wizard, you can tick the "related data" checkboxes for any related tables that you want to display for the selected item.
If you didn't tick the checkbox for a table, you can still drag the navigation property (created when you added the relationship), which is on the left side of the screen designer (with a + next to it).
To do it manually, you need to create a modeled query (a query based on a table, or on another query), to which you add an integer parameter, then add a filter based on that parameter.
I have a grid with three columns, two of which contain drop-downs, all of them getting filled from a web service result set. Now I want to allow the functionality of adding a new record in the grid by clicking an Add button present outside the gridview.
Whenever the user clicks the Add button, a new record should be created in the grid with value list filled in the drop-downs with the available options.
What is the best possible way to achieve this considering extensibility in mind.
Thanks a lot!
P.S. The data source set for the grid is a list.
Add a blank item to the list, and rebind with this new list and dummy item. That's typically one way to do it, or store the insert form in the footer of the columns. I've used that approach.
I have 4 listboxes (lstStates, lstCounties, lstCities, and lstZipcodes). Here are a few constraints:
None of the listboxes are disabled.
Any listbox can be selected at anytime, meaning there is no specific order the user has to choose.
Filtering is forward and backwards. By this, I mean if a user selects a state from lstStates, it will filter lstCounties, lstCities, and lstZipcodes. If a user selects a zipcode from lstZipcodes, it will filter lstCities, lstCounties, and lstStates.
The listboxes allow multiple selections.
Each listbox is bound to a datatable to get its initial data. The datatable is retrieved from a sqlserver stored procedure. Each listbox has its own stored procedure, for example, lstStates has one called GetStates which returns one column (State) and the ListBoxes DataValueField and DataTextField are both set to State. Similar to lstStates, lstCities is bound to a datatable which gets one column from a GetCities stored proc which is city.
Another thing I want to point out is that I am connecting an ObjectDataSource to get the datatable.
Already been asked: What is the most efficient way to filter listboxes based on selections of another in c#?
[edit]
OK, what you need to do is add an event to each [myListbox]_SelectedIndexChanged event. When the selection is changed you'll need to refresh all the other listboxes based on those selections. I assume that this will need to be handled by the database, since linking States to ZipCodes any other way would be ugly. So presumably your data for States<-->Zips<-->Counties relationships is in your db somewhere.
So you'll need to have procs in your db (or LINQ middle layer) that get States by Zips and so on. On each selection changed event, send the new selection back to the db sproc and then rebind the listbox based on the return data. You should be able to make one sproc for each one that returns all states if no zip is passed in and so on.
[/edit]
To clarify, on your initial load of the page, you are loading ALL zipcodes, ALL cities, ALL states and ALL countries?
This seems a bit cumbersome to me. This is the type of requirement I would question. (Granted I don't know that you didn't already question it or that some good answer came from it).
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "bab", "CacheItems();", true);
var ddlText, ddlValue, ddl, lblMesg;
function CacheItems() {
ddlText = new Array();
ddlValue = new Array();
ddl = document.getElementById("");
for (var i = 0; i