I'm working with a DevExpress 14.1 GridControl on WPF, which must bind to a dynamic source. We don't know the number of columns or rows on design time, so this must be calculated on the fly.
The source may be changed while executing, adding more rows, or columns, or BOTH (I could have a table with 3 columns and 5 rows, and a 6th row with 4 columns could be inserted, adding a new column to the model with empty data for the previous rows).
I was using a DataTable as ItemsSource for the grid, but it will only load data inserted on design time. If I add columns while running the app, the grid wont update for some reason.
Is there an observable object that can satisfy this needs?
It's using code-behind (not MVVM) and maybe you already tried it, but have you tried explicitly calling myGrid.RefreshData() in your .xaml.cs file? There'd be some hook-ups to get it to call at the right times depending on your data changes, but it might at least help you narrow in on the problem if it helps or not.
DevExpress support answer here may help also.
Changing from a DataTable to an ObservableCollection may also do the trick: see this.
BTW, I've found DevExpress's support ticket system to be very helpful; they seem to respond within ~24 hours for issues and questions. If you're still able to get support for your license & can't solve it still, I'd ask them the same question here.
Related
I'm trying to create an extended gridview class that will enable me to always have a footerrow that can be used to add data. That's the end goal.
I've tried classes that were found elsewhere on stackoverflow, but the code I found is apparently buggy (it either works when the footerrow is the only row, or it works when the footerrow is not the only row, but never both. Possibly related to the fact that I have dropdownlists in my rows). This problem was explained here: Bizarre issue with customized gridview control
The class itself is also problematic, in that the formatting is kind of messed up when the footerrow is the only row. It just doesn't look right... the color formatting is gone.
So now I'm thinking what I really want to do, is rewrite the data sources so they're based on UNION queries, so that there's always one blank row with -1 in the key column (my tables always have single incremental primary keys, so no legit row will ever have -1 in the key column), and then have a class that automatically hides any row where the value in the "DataKeyNames" field is -1.
Problem: I have no idea how to do this. :) I know how to do it in the aspx.cs code (RowDataBound event -- if(condition) {e.Row.Visible = false;}), and I know how to do it via CSS, but I don't know how to do it automatically in an extended class. I'm afraid I'm a little lost when it comes to writing extended classes.
To sum up, what I'd like to do is put an extended gridview class in my aspx code, set the usual gridview things, and have the only additional thing in my code be an added "UNION SELECT" in my datasource, and have it just automatically hide the row that the UNION SELECT provided, so that there's always at least one row in the gridview (thereby taking care of the entire footerrow not showing up problem), without me having to code anything extra in a RowDataBound event every time, because I have these gridview controls EVERYWHERE in my code.
Many thanks for any help you can provide! :)
In my application I have two datagrids connected to DB by Entity Framework. First datagrid is used only to select worker, second datagrid is to add, remove, update previous selected workers training's. Please check the screenshot for better view.
Problem is that whenever I add or remove rows from second datagrid (with training's) It's not updating rows, it update database, but datagrid control stays the same. Modifying rows works good.
What I have done while trying to solve this:
1. Checking for stupid code mistakes (misspeling etc)
2. Force to update Itemsource with : OnPropertyChanged("ToolboxList");
3. Breakpoint everything and it works...
But datagrid rows are the same...
Some clues that might be the reason but I am not sure if they are problem makers here:
enovaWorkers its not a table its a view, hr_ToolboxTalk its a table, and because you can't make association view to table they are associated with one to many pragmatically inside EF edmx file.
Second datagrid is not binded by selection from first datagrid (SelectedWorker.hr_ToolboxTalk) because whenever you want to edit row in second grid it raises Edit is not allowed exception. This is described here: master detail datagrid not editable
And since I cant and don't want to edit entitiy framework tt file I made workaround with GetToolboxTalkList() method. So please check the code.
Pasted code (some sections are cuted):
XAML : pastebin.com/h3sdbfKm
ViewModel: pastebin.com/7Vj3P5UJ
ICommand class: pastebin.com/rQAh7FM9
Thanks for the help...
Change:
List<hr_ToolboxTalk> ToolboxList;
to:
ObservableCollection<hr_ToolboxTalk> ToolboxList;
It will work, Lists dont Notify to the view Automaticaly.
I have used a ultragrid in my windows application to show records of a table of my database by set its DataSource property to the datatable that returns from that table.
the number of rows can be about 100000 rows.
Now i have 2 questions:
1) I want to let user to select several rows of this grid and then edit them all.to do this i need to know which cells of these selected rows have same values and which of them have not and then show the same columns in a form.
the first solution i thought about, was check all columns of all selected rows through 2 foreach loop.Is there any better solution for this??
2)finally when the user press save button, the updates should apply on the table.what is the best way to do this??? (Use IN command or UpdateCommand of sqldataadapter or ...)
According to my analysis,
1) you can do the grouping in the ultragrid based on which all columns you want to see and save the data. After grouping the similar columns would appear together and it will save a lot of time in data analysis and figuring out which column data are same in different rows. Once you have got the list of similar data you vcan handle them easily through for each loop or even for loop as you would be able to access the count of rows thus generated.
2) You should look at using the System.Data.SqlClient.SqlBulkCopy for this. Here's the documentation, and of course there are plenty of tutorials online.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx
One should avoid IN when no. of records are more as it affects the performance. If you dont want to use sqlbulkcopy, then you can also go for UpdateData() of ultragrid(very useful feature of ultragrid)
You can use the UltraGrid provided method call UpdateData() to update all the multiple rows with out need to track changes row by row or by cell
The UpdateData method updates any modified information in the grid, sending it to the data provider. When the update is complete, any rows that were marked as having modified data will have that mark cleared.
The UpdateMethod needs to exit from cells that are still in edit mode, this is a bug and to resolve it you will need to use it as shown below
ultraGrid1.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.ExitEditMode);
ultraGrid1.UpdateData();
More details on why to use it this way can be found here http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.Aspx?ArticleID=4220
To answer you 2nd question you will have to use the UpdateData method this way
e.g.
private void ultraButton1_Click(object sender, EventArgs e)
{
ultraGrid1.UpdateData();
this.dbRowsTableAdapter.Update(this.testDataSet);
ultraButton1.Enabled = false;
}
Again it seems UltraGrid keeps its local data pure to itself hence you will have to call the Update method of the TableAdapter, which means you will have to create a DataSet and fill it with the SqlDataAdapter.
Please see forum explaining clearly why UltraGrid.UpdateData method does not commit back to database here http://www.infragistics.com/community/forums/t/57161.aspx
I could not find any solution for my first question so i have used loop to compare all selected rows of my grid and diagnose the common values.
but i have used SqlBulkCopy for my second question.
I'm in C# Express 2010 and SQL Server Express 2008, making a winforms front end for simple table editing. User picks a table from a combobox, and a datagridview is populated with that table. There's a Submit and Reload button at the bottom of the form. It's loosely based on Microsoft's example for binding a DGV to a database.
So, I have this datagridview that is populated by a data adaptor. After it's been populated, I go through the resulting table and replace any columns with foreign keys with comboboxcolumns so it's easier for the user.
This bit all works fine. The comboboxcolumn shows up, with the correct data in it etc etc. I've set the Headertext, DataProprtyName, and Name properties to match the column it has replaced.
It DOES seem to have broken my 'submit' button that does the update command. Basically, if I change the value in one of the comboboxcolumns, I get a concurrency violation. If I change a value in any other column, it silently fails (when the data is reloaded into the DGV, the updated value vanishes).
Any ideas what the problem could be here?
If you need to see code just let me know. There's rather a lot of it as I'm a newbie and have probably done things in a horrendously messy way!
Thanks in advance.
Never mind - I figured it out - I had copy/pasted a procedure and forgotten to create a new DataAdaptor, so it was using the same one as the one used to populate the DGV, hence things went A over T...
I've got kind of a conceptual question. I am in the process of wrapping some statistics classes I wrote into WPF.
For that I have two DataGrid(-Views, currently in WinForms). In one DataGrid each row represents a column in the other. There I can set-up different variables (as in mathematical/statistical variables) with fields like "Header", "DataType", "ValidationBehaviour", "DisplayType". There I can also set-up how it should be displayed. Some Columns can automatically be set to ComboBoxColumns, some TextBoxColumns, and so on and so forth.
So, now once I've set-up these Columns I can go to the other grid and enter my data. I may, for instance, have generated (in grid 1) one Column called "Annual Gross Salary" with input of numerical values. Another Column called "Education" with "0=NoEducation", "1=College Level", "3=Universitary" etc. These labels are displayed as text in the combobox and my statistics engine behind then selects the respective value (0-3) for calculations (i.e. ordinal, nominal variables).
Sooo. In WinForms I could basically generate all the columns by hand in code and then add my data in the respective cells/rows. Now in WPF I thought that must be easy to realise. However, yesterday I got started with ICustomPropertyDescriptor which (maybe I was too thick) didn't give me the results I was looking for.
Basically, I just need to be able to dynamically generate columns (and rows) with different Layout, Controls (ComboBox, simple Input, DateTimes) based on the data that I have. But I don't really know how to go about it?
So here in summary:
DataGrid 1
Purpose is to display columns that have been specified in DataGrid 2
In rows, the user can add any kind of data in the rows below the columns that is allowed as to the columns specifications
DataGrid 2
Each row in this grid represents a column in DataGrid 1
Contains fields like Name/Header, DataType, Validation Behaviour, Default Value, Data Formatting, etc.
Also contains a function to be able to set-up how it should be displayed. The user can select from, for instance, ComboBoxColumn (and also add the available options), DateTime, normal TextBox, CheckBox etc.
After finishing adding a row it will automatically appear as a new column in DataGrid 1
I'd appreciate any kind of pointer into the right direction. Thanks very, very much in advance! :)
Look up DataTemplates. They do exactly this. The UI is determined by the related type.
Here is an MSDN article...