I have a datagrid say Grid1 and I have a datatable called Dt in the codebehind where the column names and data will be changing always. I am giving the itemssource as shown below
Grid1.ItemsSource=Dt.DefaultView;
In this case if I dont have any rows in the datatable but it just has column names but still I need to show up the column names in the datagrid.
The way the DataGrid works is to infer the automatic columns from the row data itself. If there are no rows, it doesn't generate any columns!
You can work around this problem by simply adding an empty row when the table does not have any rows:
if (Dt.Rows.Count == 0)
Dt.Rows.Add(Dt.NewRow());
Grid1.ItemsSource = Dt.DefaultView;
If you don't want to modify the original table you can create a copy first with DataTable.Copy.
Related
I am fully aware that ideally, dataset should return only relevant rows with which to bind tablix.
However, in this particular case, I am utilizing same dataset to bind multiple tables and need to perform some filtering 'on the fly'.
I tried writing logic in column visibility of each cell to achieve desired output but there is no unique condition available on cell level .
I need to bind only single row from the dataset based on my unique column value, any pointers will be highly appreciated, thanks !
Although you haven't provided any code/data samples but may be you can utilize row visibility property to filter rows from dataset with which to bind individual tables as suggested here
Is it possible to enter listview data by row instead of by cell? I would like to be able to pull data out of the listview by row using an index rather than having to create a ton of statements to pull out the data by cell, it would be easier this way.
I have a DataGrid bound to a table in DataSet A. I'm manually creating the grid columns.
Two of the columns comprise the key into a table in DataSet B and I need to display the (read-only) lookup Name instead of the IDs.
I'm guessing I use a Value Converter of some sort but don't know how to get started.
I saw this: Lookup-id-control in WPF DataGrid but 1) I need to specify the combobox's ItemSource in the code and can't figure out how to do so 2) I've got a tuple key 3) it seems there should a more straightforward way to accomplish this.
Thanks!
Dan
It hurts that the tables are in different DataSets. Can you possibly clone the referenced table into DataSet A?
If they were in the same DataSet, then it would be simple:
Create a DataRelation between the child table (the one with the foreign key columns) and the parent table (the one containing the lookup name).
Create a DataColumn in the child table and set its Expression to Parent!Name.
Add the new DataColumn to your DataGrid.
As I said in my comment, I'm falling back on Plan A which is more model/view friendly.
I think I'm just going about it 'wrong' otherwise.
I have two dimensional data with varying number of rows and columns and must display it to the user for editing. The format of the data itself is essentially described by a list of row and column descriptors with a header text for each row or column.
I derived a control from Grid that has two properties for the row and column descriptors and builds the gird rows and columns based on that information. It also subscribes list change events of the two descriptor collection to update itself if the user dynamically adds or removes rows or columns.
And here the problem occurs - when I try to modify the row or column definitions of the gird I get an exception telling that the collection is read-only. So I assume it is not possible to modify the definition after the grid has been created and shown once. Any ideas?
And just in the case it matters - everything is data bound. There is a (dynamic) collection of tables with each table containing its own (dynamic) row and column definitions and the data entered for each cell.
I did a quick test and I could add rows and columns without problems to a Grid at runtime through code, using the RowDefinitions and ColumnDefinitions collections. I don't think that bindings have something to do with the problem either.
If on the other hand you meant DataGrid, yes, that changes things quite a bit.
This is what I am trying to achieve:
DataTable populated using data from non database source
This table is bound to a DataGridView using BindingSource
The DataGridView is updated by the user, so that some cells now have new values.
Because the table is bound to the datagridview its values are updated.
How do I get only the updated rows(the rows which have been edited) in the grid/datatable?
I have tried :
DataRow[] updatedRows =
_table.Select(null, null, DataViewRowState.ModifiedCurrent);
But this always returns 0 rows. Is there a way to get only the modified rows?
Worst case:
Keep a copy of the original table
Get the new table from the datagridview datasource
Compare all rows.
Thanks!
How about this:
DataTable changedRecordsTable = dataTable1.GetChanges();
You can find more details at How to: Retrieve Changed Rows