I am having a problem with the RadGrid using Multiple Columns when I Bind a DataSource to the RadGrid. Firstly let me show some screenshots of what I am trying to do.
This is an example from Teleriks website under demos and the multiple columns (summary column) is what I am trying to achieve
This is the exception I am getting when I try and bind the control to a DataSource
This is the RadGrid I have set up in my ASP page.
Firstly I don't want to bind the datasource in my asp page. Secondly I wanted the "Product" and "Other" ColumnGroups to be used only as a Summary column and not to be bound to a datasource since these ColumnGroups are only used as headers for the other Columns.
Is there a workaround to not allow the ColumnGroups not to be bound to a DataSource while the normal columns are?
Firstly, each one of your columns is specifying a ColumnGroupName that does not exist. Your two groups are called OtherDetails and ProductDetails not Product and Other. Change them to resolve the exception.
Secondly, the GridColumGroups are simply groups, as they are not bound to any data from your datasource; they are simply for aesthetics.
Related
Background to the Question
Working in C#
I have a datagridview that is populated by a generic db method that exposes a data adapter and a binding source. The binding source is the datasource for the datagrid.
e.g. dgrid.DataSource=bindingSource;
I use the same generic db method to retrieve data from multiple tables and the same datagrid to display the data retrieved - so by varying the sqlcommand the datagrid display data from any specified db table on a SINGLE form using a SINGLE datagrid.
This reusable method allows me to displays data from any table in a single datagrid on a single form.
Logical Flow
Data from DB-->Assigned To BindingSource-->Assigned To DataGrid
The QUESTION
Typically I would reorder the columns on the datagrid using the 'Edit Columns' dialog but the datagridview in this case only exists at run-time.
Since the datagrid column names are not known until runtime ie until the binding source is invoked how do I programmatically access the column names, once the binding is complete, in order to reorder the columns and to facilitate further data manipulation?
Thanks in advance.
Just to know the column name after binding has been done, you can use :
GridView1.Columns[Index].HeaderText
I have a Telerik RadGrid on my page which is used to display loads of different result sets (one at a time) based on various queries.
I need to default the DataKeyNames property to the first column regardless of what dataset is returned.
The problem I have is the the name of the first column changes from dataset to dataset.
Is there a way to default the property to the first column regardless?
I sorted it myself. Essentially just building the grid manually for each separate report, pain but it's done now.
I've added repositoryItemCheckEdit in a xtragrid control's column. And i'm having total 3 columns in my xtragridview. From which two columns will be filled with the help of fields from my table when i'm setting datasource property of gridcontrol.
problem which is i'm facing is that when i'm changing the status of checkbox from xtragrid to checked for one time it works but when i'm checking from next row that time the previous selection of checkbox from gridview lost. It only maintain for only one row. and i want it two remain for multiple row.
how to do this?
my datatable contains two fields as TemplateTitle & TemplateBody. And my xtragrid contains three columns as two from datatable & additional column as a repositoryItemCheckEdit which is unbound column. I created columns of gridview at design time. and i've set just datasource property of gridcontrol to datatable.
thanks.
If the repositoryItemCheckEdit is unbound you have to control the CheckEdit's checked state manually using the grid's CustomUnboundColumnData event otherwise the state is lost when you move to a different row.
You must search DevExpress support center for these type of issues. These are pretty well documented and can be found easily there.
http://www.devexpress.com/Support/Center/p/B135631.aspx
http://www.devexpress.com/Support/Center/p/Q254784.aspx
Using BindingList and not DataTable or ObservableCollection solves the problem for booleans bound to a checkbox in a (DevExpress) GridView/GridControl ( Windows Forms ).
I have a DataSet that I create at runtime. I would like to display this information in a datagrid using wpf and have it display certain columns chosen at runtime.
I can get the data to display using:
datagrid.ItemsSource = dataset.Tables[0].DefaultView;
datagrid.DataContext = dataset.Tables[0];
How do I use DataGridTemplateColumn to add columns to the data grid and have my dataset's information displayed in them or other arbitrary data (numeration, etc)?
Thank you.
Check if these previous StackOverflow questions answer yours:
Generating columns dynamically in the WPF DataGrid?
programatically add column & rows to WPF Datagrid
(Here is the search I used).
Basically you need to add columns to the datagrid, and set their binding (using the Binding property). There are a variety of columns to choose from, you want one that derives from DataGridBoundColumn such as DataGridTextColumn.
Howdy, using vs2008 winforms.
I want to be able to use a slightly customised datagridview but cant think of a way to do it.
i have
1. a sqldataadaptor fill a dataset
2. a binding source bound to the dataset
3 a datagridview with the bindingsource set as the datasource.
I want the binding to allow sync between the dataset and datagridview, so i can edit data and then update to database with sqldataadaptor. update.
I want to show some custom columns that are calculated results.
And i want to show a final bottom row that is totals of all the columns in the DVG.
My problem is once the DGV is bound i cant add a custom column or row, it wont let me.
I know i could add it directly to the dataset that is the underlying datasource but then by changing the structure of the dataset i cant update to a database once edits have taken place.
or can i ???
Can someone tell me how i can add my custom columns and a final total row to a bound DGV.
Also while im here, if i click on the top of a column to sort on it, in a bound DGV, will it also re-sort the underlying dataset, so i i edit things will still stay synced ?
thanks in advance for any help
Yes, you can.
The adapter does not care about structure. It only cares about column names used in the Select/Insert/Update/Delete commands. You can add custom columns, expression columns, columns for subtotals, columns for totals, or whatever you need. Even change the order of the columns. I do advise adding a sort column, so you can keep the custom rows in the proper place when you or the user sorts.
You can do the same thing for custom rows. When you update through the adapter, you handle the RowUpdating event and set the SqlRowUpdatingEventArgs.Status to SkipCurrentRow for these custom rows. I strongly advise creating a row type column so you know which rows to skip when updating. (You can also use the sort column's value as a key to skip rows.)
There are a couple of articles on MSDN or KB that illustrate how to add total rows.
"How to sum the fields in a Windows Forms DataGrid control and then display the calculated totals in a footer by using Visual Basic .NET" at http://support.microsoft.com/kb/836672.
In my experience, manipulate the data table first before binding. Do what you need to do in order to support the grid and the grid's interface. It is okay to manipulate the data, add/change/remove columns and rows, then rebind when needed.
To be able to add additional unbound columns to your DataGridView you could also set its AutoGenerateColumns property to false and then add custom columns with the following method:
dataGridView->Columns->Add(...)
To calculate the contents of the unbound columns you can handle the CellValueNeeded and CellValuePushed events but you must set the DataGridView into 'virtual mode' by setting the VirtualMode property to true in order for the eventhandlers to be invoked.
Hope this helps a little....