Things are graceful in DataGridView but i wanted to learn how i can inherit a table and do re-factor it for each data item fetched from the SQLite database?
I have designed a table(System.Windows.Forms.Table) using the Visual Studio 2013 Designer, pretty much it was a drag-n-drop design.
The table has two column, left most column show's the data fetched from the SQLite database also it has a child table(System.Windows.Forms.Table) which has two row (table row) where each row (table row) has a textField which actually show to different database row (this is the database row) value. The right one has some buttons to trigger few events.
Here is how it looks like: http://i.stack.imgur.com/Q8Lfd.png
Now my question is, in this environment how i can inherit this table design and create multiple instances foreach data rows comes from its SQLite database file?
Demonstration: Here is a quick demonstration of what i wanted to achieve.Assume that the database table called "lists" has four items, so this application would create four instances of this table(Windows form table), insert all the data in appropriate fields in the table(Windows form table) and list them in the "Form1" form, something look like this [ did it on photoshop ;) ]
Please direct me in the right path by giving your idea and references
It's been a while since I worked in WinForms, but the concept is similar in all of the DotNet UI methodologies based upon the question from GER on the original post.
If you define a UserControl that renders the data to look like a single instance of what you have in your photo-shopped item, you can then reuse that control several times.
In your main form, you can now do a loop to add this control as many times as you need programmatically (psuedo code follows at the end).
You will also need a TableLayoutPanel (https://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.tablelayoutpanel%28v=vs.100%29.aspx) or similar for your primary form to serve as the layoutPanel.
foreach(DataTable table in Tables)
{
MyChildControl childControl = new MyChildControl();
childControl.Confiure(table); // Sets the data for the control.
layoutPanel.Controls.Add(childControl); // This call varies by UI method and what layoutPanel you are using
}
Caveat: I can't remember enough about WinForms to remember how to set the grid row/column settings on the control. You get to do some research on that one if this works for you.
Related
I would like to write a software which shows database contents in a Forms application. To make it easier to explain, I'll use a shopping list as an example.
I have a number of lists in one table tLists
I have a number of tProductPackages in another table
A list can consist of many productPackages and one productPackage can be in many lists. This m:n relationship is reflected in a separate table named tListProdPacks.
A productPackage contains a product. A product can have several productPackages. In every tProductPackage table entry, there's a foreign key FK_ProductID which references an entry in a table tProducts.
My forms application should navigate through all the lists using a BindingNavigator. In some bound controls, it should display the details of the selected list. This is working fine. (Just bound controls.)
All the list contents (entries in tListProdPacks for the selected tLists element) should be shown in a DataGridView. This is also working fine. Also the details of the productPackages (tProductPackages items i.e. one hop more to the next table) are displayed correctly. In this table he product value is available as ID (FK_ProductID) (foreign key to tProducts).
Is there a way to show the product name (contained only in tProducts) in the DataGridView whose DataSource is tListProdPacks?
(It's easy to display tProductPackages members, as the primary key from tProductPackages is referenced it tListProdPacks and using this ID I can show all other details from tProductPackages by just keep using the same valueMember but use different DisplayMember values for the single DataGridView columns [using dropdown controls in the DGV].)
But when jumping one table further (i.e. when jumping to the tProducts table), this does not work anymore.
I know that I could just create a custom query (join, view) to get exactly what I want, but then I cannot update the database from the dataset anymore.
Does anyone konw how to accomplish that?
(I guess that there's some easy way provided by the framework and I just don't see it, right?)
I'm not sure if I was able to describe what I would like to accomplish good enough. If not, please help me what to provide in addition.
Best regards,
Tom
u can relate the tables using joins if they contain primary key foreign key relation . using joins u can retrieve a single result set containing all the fields which u might need.
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.
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. :-)
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...
I would like to know the best way to use a datagrid control linked to a combination (join) of data tables in a way that both simply allows both display, creation of new rows in underlying tables and deletion.
The datagrid appears to offer the latter capabilities but I have not found a way that I am happy with to do more than just display on one grid and offer specific separate edit create and delete facilities.
Suppose for the sake of illustration that the database contains:-
Customer Table
* CustomerID
* CustomerName
Order Table
* CustomerID
* OrderLineItem
* OrderLineQuanity
And that I want to lose the CustomerID for display purposes but would like to be able to create new customers and delete existing ones, perhaps with a confirmatory dialog.
CSharpAtl is correct, use a Master-Detail control. An example of using one in a WinForm app is at http://msdn.microsoft.com/en-us/library/y8c0cxey.aspx.
WinForm DataGrids support add, edit, and delete of both Master and Detail records. As for your question about what happens if you change a Detail record so it matches a new Master; that is not possible. By design a Detail row only contains records that match the Master, you cannot (for example) change an order to belong to a new customer because the Detail row does not contain any customer information.
If you want to move a Detail row to another Master, you have to create a new Detail row for the new Master, copy the data from the old Detail row, and delete the old Detail row. If you're ambitious you could support Cut and Paste or Drag and Drop of Detail rows, but internally you have to Create/Copy/Delete.
If the relationship is 1 to many you can go the route of using Master Detail. [link text][1]
[1]: http://msdn.microsoft.com/en-us/library/aa479344.aspx/"Master Detail"
If I understand your question correctly, you have a query that performs a join of several tables which you display on a single grid. You’d like the user to be able to manipulate that grid and have the underlying tables reflect the changes.
An approach is to solve this problem is to implement stored procedures to perform the CRUD operations. The stored procedures will contain the logic to insert, update and delete records from all of the required tables. Each procedure will need to have a parameter for each bound field on the grid. Set the procedures to be the insert, update and delete commands on your data source.
So imagine if you are adding a new record to the grid. The grid calls the insert command, passes the parameters to the stored procedure. Then within the stored procedure you’ll create the logic to determine if the new line in the grid requires a new customer or if it’s an existing customer then adjust the operation accordingly.