Well, im a beginner and im having some problems with the code. On the display it shows System.Data.Objects.ObjectQuery 1[System.String](on the left).
Im trying to merge two diferent tabels by taking Naziv from a different table and adding it to the grid.Another table for the combo(three tables, on the right) And here is the complete code from the class:
KozmetikaEntitiess tretmanProdukti = new KozmetikaEntitiess();
public frmTretmaniProdukti()
{
InitializeComponent();
}
public frmTretmaniProdukti(frmMain parent)
{
InitializeComponent();
MdiParent = parent;
}
private void frmTretmaniProdukti_Load(object sender, EventArgs e)
{
cmbTretman.DisplayMember = "Naziv";
cmbTretman.ValueMember = "TretmanID";
cmbTretman.DataSource =
from tretman in tretmanProdukti.Tretmani
orderby tretman.TretmanID
select tretman ;
}
private void cmbTretman_SelectedIndexChanged(object sender, EventArgs e)
{
int TID = int.Parse(cmbTretman.SelectedValue.ToString() );
tretman_ProduktiBindingSource.DataSource =
from tretmanProdukt in tretmanProdukti.Tretman_Produkti
where tretmanProdukt.TretmanID == TID
orderby tretmanProdukt.ProduktID
select tretmanProdukt;
grdProdukti.DataSource = tretman_ProduktiBindingSource;
}
private void tretman_ProduktiBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
Validate();
tretman_ProduktiBindingSource.EndEdit();
tretmanProdukti.SaveChanges();
MessageBox.Show("Снимено", "", MessageBoxButtons.OK);
}
private void NapolniCombo()
{
DataGridViewComboBoxColumn colProduktID = new DataGridViewComboBoxColumn();
colProduktID = grdProdukti.Columns["ProduktID"] as DataGridViewComboBoxColumn;
colProduktID.ValueMember = "ProduktID";
colProduktID.DisplayMember = "Naziv";
colProduktID.DataSource =
from produkt in tretmanProdukti.Produkti
orderby produkt.Naziv
select produkt;
}
private void grdProdukti_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
grdProdukti.CurrentRow.Cells["TretmanID"].Value = int.Parse(cmbTretman.SelectedValue.ToString());
}
private void grdProdukti_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (e.ColumnIndex == 1)
{
int PID = int.Parse( e.FormattedValue.ToString()) ;
grdProdukti.CurrentRow.Cells["Produkt"].Value =
from tretmanProdukt in tretmanProdukti.Produkti
where tretmanProdukt.ProduktID == PID
select tretmanProdukt.Naziv;
}
}