Devexpress gridview, binding to data with foreign key required - winforms

I have a problem with binding data to Devexpress Gridview, one column refers to a foreign key in another table which will be determined after the insert
the application is for entering an invoice and its items
I can insert invoice metadata but its items are in GridView and it gave me this message when I tried to addnewrow
enter image description here
how can I assign a default value to the column in the Items table until I send them to database?
Thanks

Related

Problem with Showing Query Results on a Form

I'm having a Projects lists Continuous form where the form's Record Source is based upon a table.
I have a requirement to display a field from another table which is linked back to original table using its primary key. The primary key is a AutoNumber field, but when displaying in the form I've used Input mask something like this "TMG/FEA/"0000.
So I made:
a unbound list box
and made the Row source as the query which displays the relevant information from second table
This query was created using primary key displayed in form (I mean the [Forms]![Form Name].[Field] ) as the where clause.
But the results returns blank. I'm Stuck here. I'm not sure if the query is not working due to the Input Mask or because of something else. Please help me. Thanks in advance
You should add to form field listbox, and set following values:
Data: primary key of your first table
After this, that field will duplicate ID value. Now you should transform RecordSource of this field in order to see contents from second table. So you should set:
SELECT [PrimaryForeignKeyID], [DetailedField] FROM tblSecond;. Actually I don't know the contents of your second table. Whereas PrimaryForeignKeyID is a field that links second table to first, so-called FK.
After this set following properties of list box:
ColumnCount = 2
ColumnWidth = 0;2
AllowEdits = False
Save form and open it for viewing.
In this case, your listbox will show the associated contents of second table on form.
So to my mind it is better for you to do such simple tables and forms, and you'll realize idea.

Combobox showing Foreign Key not Reference Value

I have a table with a combination of Text Boxes and Comboboxes all bound to fields in a Users table.
The combo boxes are used to select items such as Location, Access rights and Title which are all listed in seperate tables.
However as the values for Location, Access rights and Title are stored in my users table as the integer Primary keys from the related tables this is what is being displayed on my form.
How do I set the combobox field to display the Loc_Name rather than the Loc_ID but still be bound to the original users table?
The second problem I have is that when I select the dropdown for the combo box I get the List of Locations (for example) which is fine and when I select the valid location it displays the Loc_Name in the combobox field. The problem here is that because the combobox is bound to an integer type field in the Users table the form will not accept the String Loc_Name only an integer value.
Am I going about this the wrong way????
Details of settings:
The Location combobox on my form is bound to the Location field in my users table which stores the foreign key integer value from the locations table.
The ComboBox datasource is set to the Locations Table Binding SOurce
The Combobox Display member is set to Loc_Name
The Combobox Value Member is set to Loc_ID
The Selected value is set to (None)
Sorry. Should have put this here.
Looks like I might have been going about it the wrong way. Instead of referencing the valueID with the combo box I had to create a SELECT that join the two data tables and display the Joined data. On update the combobox had to be set to reference the original ID Field. Seeming like a very roundabout way of doing it. No where near as neat as Access.

Access 2007 - Query displays Combobox Primary ID rather than Value

I am writing a query based on a Table which is populated via a Form with several combo boxes. The information is stored in the Table as the Primary Key of the Combobox value which I understand to be correct. However, when I run a query or report based on the Table, I would like to display the Combo box Value rather than the Primary Key ID. Is there a way to do this other than using a Lookup to the combobox in the Table?
Thanks in advance for your help.
JB
It depends on how you have your combo boxes set up. Are they populated from a list in the field or from another table?
If from a list you entered in the table field where the value is stored, you should just store the value.
If they are from a separate table, then set the relationship from the combo lookup table's primary key/ID to a field in the main table that stores the combo selection which should be a number type. In a query, add both your main table and the other table where values for the combo are stored and add the value to your results from the combo value table along with the data from your main table.
It's a little confusing to say you want to query a combobox value, essentially you need to look at the SQL source of the combobox first in order to see where it draws it's values from. You then need to link this back to your query that you are running, as long as there is a common PK/FK between these then you can just perform an INNER JOIN on that.

MVC 3 Entity Framework - new database column not populating corresponding property

I am creating a web app in MVC 3 using entity framework, and recent spec changes have required I add a new column to one of the database tables (a record creation date).
I have added the new column and populated it with values for my existing records, and updated the model in the entity framework. When I look at the object corresponding to the table with the new column, I can see a property for this new data: however the data for that property is not being retrieved.
Just to clarify:
I added column "CreatedDate" (datetime) to table "Orders" in my database
I populated this column with values for my existing records and set it to "not null"
I updated the model in entity framework
My model "Order" now has a non-nullable property "CreatedDate"
I populate a list of orders using LINQ ("from o in DB.Orders select o")
For any entry on my list, entry.CreatedDate returns "01/01/0001 00:00:00", not the value I have entered into the database.
What's going wrong?
EdmMetadata table?
Do you have an EdmMetadata table in the database? As far as I know, this table contains a key that is signed by the structure of the database. So if this value is not changed, the code could not be seeing the change. Good news is that this table is no longer needed:
modelBuilder.Conventions.Remove<IncludeMetadataConvention>();

WPF DataGrid Lookup Column Value

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.

Resources