I dynamically create my gridView from DataTable. Now when I add paging to it, I must Auto Generate Columns. As soon as I do that, the gridview data is duplicated.
1.5K+ records each 150 Columns duplicated doesn't exactly look quite right.
Anyone's got a clue on how to add paging that actually won't mess everything up?
PS: I fire up LoadGridView() event on Button_Click.
This is a very simple example on how it is done
Related
After adding a row to a DataGrid, I would like to update my DataGridView (with the input source of said DataGrid) using that new row. However when I use .Update() and .Refresh(), the whole of the grid gets re-drawn. When refreshing relatively quickly (around 4 times per second), this creates an unpleasing jolty effect. I would like to find a way to add my row to the DataGridView, without re-drawing the whole thing, therefore removing the DataGridView.
C# Winforms
I think what you are looking for is a data binding.
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-bind-data-to-the-windows-forms-datagridview-control?view=netframeworkdesktop-4.8
This means the DataGrid is bound to e.g. a DataTable.
I've set up a simple data bound gridview that is populated via the autogenerated code for winforms. It is filling based off of the dataset I point it at.
I've updated the underlying database it's supposed to be filling off of to add an additional column to a table. However this added column is not appearing in the gridview.
I have deleted the datset and rebound it and can't find an answer online but am probably searching with incorrect terms. Is there a way to refresh the dataset in some way?
How the gridview is being filled is by:
this.xTableAdapter.Fill(this.DBDataSet.tableName);
I imagine there is a simple way to refresh the underlying dataset but cannot for the life of me find what it is.
This link had the answer. I needed to go into the dataset designer view and right click on the get, fill() query in the query area for my table. Doing so allowed me to modify the query that built the dataset, adding in the missing column.
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! :)
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.
I have a gridview and sqldatasource.
I want to display in a label, the number of rows from the gridview which contains a certain value in one of the columns (in the form_load event)
I thought about looping through all columns of the gridview but it will take a lot of time for this and maybe there's another way of doing this.
Can someone help me finding the "other way"?
Thanks,
Best solution would be to let the database handle filtering - you'll get much better performance that way than looping over the data on application server.
Perhaps create another SqlDataSource with an SQL statement containing appropriate WHERE condition and bind it to your label?