TreeView in GTK# updating the columns in ListStore - c#

So I have a TreeView in GTK# and I preload it with an empty TreeModelSort (no columns.)
At runtime I let the users select the columns they'd like to add and when the button is clicked I create a new ListStore with these columns, from that I create a TreeModelFilter and TreeModelSort. I then append the values to that TreeModelSort by using reflection to pick up correct values based on columns. That all works fine and I end up with a TreeModelSort with the columns and data I am interested in.
The problem arises when I try to replace the old TreeView.Model with the new one I've just created. There are no exceptions and it replaces it fine but the new columns and data don't show up in the table.
Any ideas on what I could be missing?
Is what I'm trying to allowed or do I need to remove the TreeView from the screen and replace it with a new one?
Edit: Or even if I could have all columns in the list store but only show a few selected ones in the TreeView, is that possible? All the tutorials I've found have exact one to one mapping of columns between ListStore and TreeView. Any ideas?

(no experience with GTK#, but lots of experience with gtk in other languages).
It seems to me you might be mixing views and models here. To make columns visible in a view, you not only need to have them in your model (as you are doing), but you also need to add cell rendered to your view, binding them with specific columns in your model.
I'll show some pseudo-code below, and let you convert to gtk#:
create a new GtkTreeViewColumn
create a new GtkCellRendererText.
add it to the column with a call to gtk_tree_view_column_pack_start
add attribute to the renderer, for instance to tell it which column of your model it should render. For instance:
gtk_cell_layout_add_attribute(column, renderer, "text", 0)
to show the first column of your model (interpreted as text)
In fact, I would not implement customizable columns the way you do. Instead, I would have, from the start, a model that contains all possible columns and their values. Then when the user choses which columns to display, I would add (or remove) cell renderers and/or GtkTreeViewColumns from the view.
One of the benefits is that you could have several views of the same model, each displaying a different set of columns.

Related

Reusing Radzen DataGrid within the same layout under an if statement

I am trying to display a Radzen table on a page.
There are three scenarios which output the same table with different data.
Normally, I have to code the table three times, and assign different data to the corresponding table.
But I want to avoid repeating the codes as it may make the project harder to manage.
To use Radzen, I have to populate "#ref", assign "Data" and specify "TItem".
Can I somehow use a string or anything to represent TItem and reuse one Radzen table under an if statement?
<RadzenDataGrid #ref="obj" Data="IList" TItem=Class>
...
<RadzenDataGrid>
There is no way to reuse a Radzen DataGrid with different TItem(s).
Therefore, you should clone items into a common class and display them in the 'reused' DataGrid.
Then, you can edit, add, and delete the data with the corresponding TItem.

How do I set the content of a label to a database table cell in WPF?

I have built a program in WPF using Visual Basic that allows users to select from a series of items. The list of items may change as I add more items or remove older ones. Originally, I would just add and remove these items in the project code, and rebuild the executable.
Over time, however, the list of items grew and became tedious and impractical to maintain in the code. It occurred to me that it would be easier to store the items in a database table which the program can read, and the list can just be updated by adding and removing items from this database.
I have the database built, and I've added it as a Data Source. I have the data connection set up and everything is ready to go.
What I need to know is how to set the Content property of a label to a cell from a table in the database. I want to do this in the codebehind, not in markup (XAML).
My guess is that I will need to set up a sort of query with a for loop to find the cell I want.
The name of the database is ItemsDB. It contains a table called ItemsTable, and the fields in the table have a unique ID (key) with an AutoNumber data type. The column containing the data I want is named ItemLabel.
So, to sum it all up, I want a label to show the content from a single cell in the database, specified in the codebehind. Either C# or VB is fine.
EDIT
I guess I should've mentioned that the labels themselves actually function as buttons, and I don't really want to display a ListView if I don't have to. I know it's not helpful to not have any code posted, but I don't even know where to start, so there's no code to post.
Took a while longer than I expected, hope this is still useful. So, what you want to do is iterate through a collection and create a new Label for each row.
You will need a container for the Labels, I used WrapPanel, but you can use any Panel you want. I'm replacing your Data Source with a simple DataTable, you'll get the point from this:
foreach (DataRow row in YourItemsTable.Rows)
{
Label newLabel = new Label();
newLabel.Content = row["ItemLabel"].ToString();
// If you need some events, attach the handlers here
yourParentContainerPanel.Children.Add(newLabel);
}
This should be all you need.

WPF - How do I bind DataGrid where a column act as pivot and rest form rows and columns

Please pardon me for this vague header, please feel free to edit it and make it more meaningful. I will try to explain my problem as much as I can here.
I have a collection that is bound to dataGrid. User can neither add nor remove any object from it they can only add data into it.
So lets say my collection is ...
Column1--Column2--Column3--Value
Only Value field is editable and rest are static and readonly. This list has like 10,000 elements in it and hence makes its really difficult for users to add and use data in this grid.
-- Requirement --
Requirement is to have Column1s values to be split in to tabs ( which we know are only 4 )
Have column2s values as Rows
Have Column3s values as Columns
And Column4s as editable cells ..
thereby making an fairly easy to use UI
---- Current half cooked solution --
So far I am planning to create a new object that would map to this new grid. So I will have a list of col1 that will be bound to tabs a list of col3 as for columns with all values of col4 in it and there will be a static first column with list of all values of col2.
-- Help --
I am here to ask if dataGrid is capable of getting manipulating in such a view somehow so that I don't have this dependency on new object ? can I do this more efficiently because its just visual representation that I want to change, which should not need creation of new type.
All suggestions and critics welcomed. apologies if anything is not as per stackOverflow's rules and regs..
happy to edit anything if needed.
I'm not going to pretend I fully understand your scenario. Some columns as rows, other columns as columns etc. But I am still fairly sure DataGrid does not do what you want.
can I do this more efficiently because its just visual representation that I want to change, which should not need creation of new type.
Remember the ViewModel is an abstraction of the view. If you have to do a lot of work to shoe-horn the viewmodel into a view, including complicated binding logic or yucky backing code then that's not a good abstraction of the view. So you should have a ViewModel that represents the data closely to how it is to be displayed.
Part of the problem sounds like you want dynamic columns. If so, see this answer for binding a grid dictionary https://stackoverflow.com/a/14172511/360211

How to generate freeform rdlc reports with one page per row

Given a data set containing multiple rows, from within a .NET console application I need to generate a report on a single page for each row, sending those pages directly to the printer.
I am attempting to use Microsoft Report for this by attaching it to a data set and placing TextBoxes where I wish. Generating the report and sending it to the printer are not a problem. Unfortunately, the data only seems to be available in aggregates -- First, Sum, Last, Max, etc. I cannot latch the text box to a bare field.
Some poking around here and other sites seems to address this, but only when the data is presented in a table. One post even said without elaboration, "My mistake was using Text Boxes"
Am I using the wrong tool for what I am attempting to accomplish?
I ran into the same problem and managed to solve it. The solution seems a little convoluted to me so don't quote me on the "right" way to do this, but here is what I did:
Make sure you have a Dataset defined for your report.
Add a "Table" control to the report. This seems to be needed in order to iterate the rows in your Dataset.
Delete the header row and two of the default columns from the table so that you are left with a single row with a single column.
Expand the table to the width of your layout and make it as tall as you will need for your "free form" layout.
By default, there is a TextBox inside the table cell. Right-click the empty table cell and choose "delete" to remove that TextBox.
Drag a "Rectangle" control into the empty table cell. It seems to automatically "dock" to the width/height of the table cell.
Now you should be able to drag the fields from your DataSet (TextBoxes, etc) into the Rectangle to produce the desired layout.
Note that I am in the early stages of using this approach so I'm not sure if I am going to hit any walls... but for a basic report that uses TextBoxes and a page break after each "row" it seems to be working ok.
Or you try to use a list.
In the list you can arange textboxes (and other controls) as you want and they will be filled for each record in the recordset.
This work for me. :-)

Dynamic DataGrid columns in WPF DataGrid based on the underlying set of data (and their type)

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...

Categories