I'm trying to create a simple data application for a school project, in which an user selects data from an databound combobox for and fills out several textboxes for it to be committed to the database. However, when after I databind the combobox, and select an item, it simply will not let the user select something else. It's impossible to let edit anything, since the focus doesn't go away from the combobox.
What is happening?
Nevermind, found the solution. All I had to do was to set the ComboBox's CausesValidation to false.
Related
I would like that when I click the combobox to see all the items that I can select, before show the items, serach in the database the items that it has to show.
But I don't do that when I click the item that I want to choose, that it good be the event selectedItem.
But I am not sure which is the event when I click the combobox to see all the items.
I am using MVVM Light.
Thanks.
This is DropDownOpened: https://learn.microsoft.com/pl-pl/dotnet/api/system.windows.controls.combobox.dropdownopened?view=netframework-4.8
But I think you should consider doing it in a different manner.
When user clicks combobox to show its items, he expect that the items... will be shown :) But you are going to load them.
I suppose you use some kind of filtering data, and when user clicks the combobox, then proper data gets loaded. I would consider loading them on changing the filter. I think that loading data on combobox click is too late.
I'm pretty new to c# and Winforms and I'm wondering what is the best approach to the following screen design.
I have a window that contain a Datagrid wich would be read-only. Beneath the grid, I have the detail of the records in differents fields (textbox, combobox, checkbox).
What I want is that when the user click on an item in the datagrid, the data will be shown in the detail fields.
That part is pretty easy, but I want to be able to update the fields automatically, wich means, I would prefer to not have to press a Save button.
Let's say that I click an item in the datagrid, change some value in the detail fields and the I click on another item in the datagrid, then I also want to perform some validation and calculation before the record get updated.
What I was thinking at first was to get the button for "new", "edit", "save" action and lock and unlock the fields accordingly and keep a flag to know if i need to insert or update the data, but then I realized that I would prefer to not have thoses button and have the save performed automatically.
Is there any sample somewhere that does what I want?
Also, would you guys using the built-in databinding functunality or just use a dataset object in code?
Pretty common scenario.
On selected row change of grid you know which datarow you shoul bind to the other controls. when same event happens again you validate and save or cancel in case of errors.
You can make use of DataGridView.CellEndEdit Event to get the new value and DataGridView.CellBeginEdit event to get the old value and update your data if there is any change
There is a WPF DataGrid with columns that have checkboxes. These checkboxes are already bound to some data source. What we want is a checkbox for each column that checks/unchecks all the checkboxes (and as a result updates the data source so that all the values are the same).
Existing solutions on here work if there isn't an existing datasource - but we have effectively two, the 'select all' checkboxes and the actual data that the other checkboxes in the rows are bound to, if that makes sense.
If we could use a trigger or somesuch instead of 'code behind' that would be ideal. Is there a declarative solution?
Make your CheckBox's Click event point to a Command in your ViewModel that iterates your DataSource and sets IsChecked to true.
The standard solutions can work with a databound grid. An example is found (http://www.4guysfromrolla.com/articles/120810-1.aspx). This example if fully client side.
The problem comes when you postback, but that is only a problem if you are not persisting the check all back to the database and refreshing the data you are binding. In those cases, you need to ensure something is passed back to indicate the check all so you can dynamically set the boxes again after a postback.
I'm having issues using a GridView as a ListView's View, what I want to do is fire an event when a user makes a selection from a combobox within the Gridview and pass the selected item within the event.
My first issue is that when the user clicks the combobox within a row, the row isnt selected (meaning the selecteditem stays null unless they click elsewhere first). Is there a clean way to do this without trying to catch mouse clicks or anything?
Secondly theres no selectionchangecommited event on a WPF combobox, is there a cleaner way to check if a user has manually selected an option other than checking if the combobox is enabled?
Thanks
I am seeing a similar behavior. My hypothesis is that one or more layers of the DataTemplate of each item in the list is swallowing the RoutedEvent that should have resulted in a new selection. Is it possible to, in a generic way, tell the items in the DataTemplate that they should never stop the event from bubbeling or tunneling further, without having to override every focus-triggering event handler in code behind?
I 'solved' my issue by using the WPF Toolkit grid (http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29117) and a series of selected items, which is probably a cleaner solution anyway.
Doesn't explain the behavior of the GridView, which is to me unusual
Original link has died, believe this to be the one https://github.com/xceedsoftware/wpftoolkit/wiki/DataGrid
I have a formview with an insertion template. In this template there is a drop down list with a number of items I want users to be able to select from. Beside the drop down list there is a button which I am using to add the selected item from the drop down list to a gridview which also exists in the insertion template.
My problem is that when I click the button to add the selected item from the drop down list the selected item, index or value from the drop down list are not available. I am using a OnClick event handler to catch the event from the button click but I suspect there is some kind of refresh of the template going on here which I am not understanding as nothing appears to be accessible from the button event handler. I don't believe a postback is occurring as I have disabled the CausesValidation property for my button.
It seems like you are binding your DDL on postbacks as well. If the ddl data isnt hardcoded and you have the call for your ddl databind function in the Page_Load, you need to call the function like this to ensure it is not bound on postback:
if(!IsPostBack)
{
BindDDL();
}
Otherwise we need more information to help you and please post your code.
If you are clicking an asp:Button with an OnClick eevent attached to it then you are posting back to the server, no matter whether or not CausesValidation is true or not.
Are you binding data to the DropDownList? If so and you are rebinding it on postback then you'll not have the selected item you're expecting.
Can you paste us the code here?
I would have to see the code, but it sounds like you are getting a rebind prior to pulling the chosen items. One way to examine this is to add a watcha nd then make sure you code in the various ASP.NET events and then watch.
Without seeing what you are doing in code, I cannot tell if this is a drag and drop anomoly or something you have coded in. But the symptoms you are describing fits the typcial bind in Page_Load scenario, which is what jmein was aiming at.
So it turns it out it was all my fault. The formview control I have is contained in a panel which did not have view state enabled. This was preventing the drop down list from remembering the item I had selected it seems.
Thanks all for your comments and suggestions.