I've not been doing much WinForms programming for the last few years, so I'm a bit rusty. Right now I'm having trouble with something pretty simple. I have one table of data that includes two foreign keys to two other tables. What I want to do is simply display a list box that shows a name field from the table and several text boxes below, which display the rest of the data in the row corresponding to what is selected in the listbox.
I tried simply setting the datasource on the listbox and then binding the detail textboxes to columns in the same datasource (using bindingsource), and that seemed to work fine. However, when setting the comboboxes up for the two foreign key columns, they did not reliably change to display the correct value as the user selected different items in the listbox. Additionally, when I made any changes in the detail textboxes, the HasChanges method on the dataset still returned false.
What do I need to do to get this to work correctly? Is there a good example out there somewhere? Google just seems to return a ton of results showing how to populate a simple listbox.
I saw this had been up for a few days so I'll provide what help I can...
I'm a bit rusty in that area as well. However, the place I always go back to for a refresher is the Forms over Data Video Series by Beth Massi. They are short, sweet and to the point. My guess is that you'll find what you need within the first few videos.
Disclaimer: The videos were done using VS2005. The fundamentals are solid though. While one or two minor things may have changed, WinForms databinding is pretty much the same as it has been for a while.
HTH and good luck!
Related
I've got a massive UI that I'm designing. The way that my employer wants it, there are at least 100 labels. Now, I've always thought that in cases like this, breaking up the UI into smaller custom controls was the ideal way to go. However, someone recently told me that custom controls are really only for code re-use. What is the actual suggested practice for this?
EDIT
The finished form will look like this:
Now, I'm using WPF for the UI, and I'm thinking of breaking this down into smaller bits.
Based on your image i see some repetitions, each of this repetitions could be a custom UserControl
But it depends on the usability is it easier to write a custom UserControl so do it but if it would reduce the readability of your code and it also adds additional complexity don't do it
here are an example of what could be separate UserControl's
the green ones are possible useful encapsulations of logic
the orange ones maybe need some not market stuff (don't know enough about your software)
the red ones are the maybe's based on the intern use (from the visual part they are repetitions so the should custom UserControl)
Since your UI is read-only, I'd suggest using a grid.
Are you new to WPF? To break the View into bits WPF offers you CustomControls and UserControls. They are two very similar things yet completely different from each other. CustomControls are Buttons, Labels, TextBoxes, DataGrids...etc. They are basically simple stand-alone controls. UserControls are groups of stand-alone controls serving a purpose such as example a Button and a ComboBox next to each other so user can select something in ComboBox and confirm that by clicking the Button.
If you wish to display data from database I suggest you DataGrid which will give you a table-alike look with rows and columns and all that. If you wish to place few buttons next to DataGrid on which the user may click to insert a new row or to edit a certain cell then I suggest you to wrap all that with a UserControl which you can reuse in other places where you have to display and change data from database too.
You should be using a datagrid and can customize its template to render individual cells as Textblock (lighter version of Label) from a rendering perspective. The main difference between Textblock and Label is very minor things such as access keys and disabled state behavior. But from a WPF object hierarchy - Textblocks are much lighter. But besides that point - from your employer perspective - once you have customized the grid template and render them (so as they look as textblocks/labels) - your employer should have no problems.
Also as somebody suggested above - if you want to logically break sections of the UI since they maybe coming from a different table in db - then User controls is the way to go (for maintainability of code)
Let me know if you are looking for more technical details or need help further technically.
There is nothing wrong in making and using custom controls or user controls or defining some data templates which will be reused depending on how your data is organized.
For sure the UI looks pretty messy and some sort of grid should be used with templates for example where there is similar data. I also have the suggestion and first think about the data and the functionality before starting and let the UI be driven by that. For sure you will the reuse controls/templates. If you think in front on the model and behavior the UI can afterwards more easily changed.
Create your viewmodel correctly, implement the functionality in commands, use bindings, after that the UI will come naturally, reuse controls, use several grids, make the UI more user friendly using several regions, tabs, windows or anything that makes the user more comfortable.
I am trying to create an autocomplete textbox in WPF. What i found is http://weblogs.asp.net/okloeten/archive/2007/11/12/5088649.aspx. It seems quite close to what i needed. The only thing missing in this is when i press down arrow key after typing some characters it does not allow to me select an item from the narrowed list in dropdown.
Please give me some pointers how can i allow to select item using up/down keys after filtering list using some text input.
Regards.
There have been many implementations already for an autocompletebox. So as swiszcz stated, look for a working & well documented project. You need not spend time on trying to tweak some particular code for too long, when other options are available.
I have used an AutoCompleteBox implementation by Aviad P for many projects and found it easy enough to tweak and suite my needs. I feel the code is well documentated in the blog article itself. Also it uses a textbox & listbox (rather than a combobox) which is in my opinion, a better choice.
I should start out with the disclaimer that I don't have a lot of info into this problem, but I wanted to put a feeler out to see if anyone else had this problem. I started a new job and some folks here are using Infragistics WPF datagrid. The grid was selected because of the visual flexibility, but apparently when there are large amounts of rows in the grid, things begin to perform very poorly. This is possibly due to implementation (not sure, haven't gotten into the code yet) and shouldn't be taken as a negative on the control.
Has anyone else encountered and have any advice I could pass onto the developers? Thanks in advance.
Edit*: I think introducing paging might not be an option. The grid is being used in such a capacity that it is displaying data streamed into it. So the use case is that the end user is monitoring 50-100 rows that are updating with new values intra-second (aka - think running stock tickers instead of flipping through a result set)
I'm having problems with XamDataGrid as well. Although I don't have the right version to attempt this, you might try changing to the high-performance hoverless style, and suppressing events, as described here:
http://blogs.infragistics.com/forums/p/48307/264160.aspx
The rest of the suggestions are a lot more specific and handle particular schemas and use-cases.
Here's a bit more of an overview of Infragistics optimizations:
http://help.infragistics.com/NetAdvantage/WPF/2010.3/CLR4.0/?page=xamData_Performance_Optimizations_Overview.html
I am using the Xceed DataGrid, but I recently discovered our DataGrid was binding to a View (DataGridCollectionView) and not to a datasource (DataView/DataTable).
This meant we replaced the entire view for each refresh.
By binding to a DataTable, my code now refreshes the DataGrid instantly with a few thousand rows where it use to take 1-2 seconds.
As most grids are similar. please verify how your code is binding to the data that goes into your DataGrid.
I posted some code here in case that helps.
The approach is take is to enable virtualisation - this ensure that only the information on the screen is involved in a repaint. See no problem with 100 rows being continuously updated.
In Excel, there is this feature for filtering the cells of a column.
How can I implement excel like FILTER feature in Silverlight Datagrid?
Please advice. Thanks
AJ
Good question - this is a good feature, but not one that can be implemented in 5 minutes.
You don't want to be overriding the rendering of the standard datagrid in any way (too much work), so you need to take a slightly different approach. One way to do that is to draw your own 'header' above the top of the grid - just a grid, with a border and a stackpanel will get you started. Then you need to enumerate the visible columns of the grid, and create a dropdown corresponding to each, and add that dropdown to the stackpanel. Using a simple linq statement you can get a list of the distinct values in each column. When the user selects a value from the dropdown you can then filter the grid's datasource using that value in a LINQ statement.
In reality this is probably going to be at least a week's worth of work to do properly. If you take the cost of that development and the cost of the testing, and measure that against the cost of a good component suite where they already have filtering built in (most of the major vendors do), then unless you are working for a very low hourly rate you will find it is cheaper to buy the components - it is probably safer too, as the components will be well tested and realtively bug free.
Edit (some time later): what i should also mention though is that if you only want to do this on a couple of columns then you could consider using a column header template. If you take this approach though you will also have to do things like copy the various mouse related animations or transitions that might be part of the original colunm header, just so you can keep some consistency across the top of the grid. Personally i would just go with option one and give the user the ability to filter on any of the columns.
In an SL3 datagrid, is it possible to have every cell of the grid editable?
I need to create a UI that's similar to an Excel worksheet. Upon a button click, the entire collection of objects would be submitted as opposed a single object or cell.
Is this even possible, and if so how would I go about achieving it?
Thanks.
I guess the reason why this question has sat here 4 hours with no answer is that we all asking ourselves "Have I missed the problem here?".
First of all you can't actually "edit every cell concurrently", after all when you hit a key on the keyboard only one control is going accept that is input, the one with the focus.
"Excel worksheet" behaviour is exactly what you get from DataGrid if you let it automatically generate the cells.
So this question is really about the object you assign to the ItemsSource property. You really need to tell us about what you are using to store the data.
The truth is your requirement is quite easy to deliver especially if you include WCF RIA services. Ulitmately you get a "Data Context" which you can edit in various ways and then submit changes at whatever point makes sense for your application.