Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi people! I am pretty new in all this. And I don't have so much time because of my little baby. I appreciate any help I can get.
Here is the code.
XAML:
XML
<window x:class="Aukcija1.MainWindow" xmlns:x="#unknown">
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Auctions" Height="350" Width="525">
    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"> 
    
    <grid>
DataContext="{Binding}">
        <datagrid> AutoGeneratedColumns="False" EnableRowVirtualization="True" Height="264" HorizontalAlignment="Left" ItemsSource="{Binding}" Name="aukcija_bazeDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="503" SelectionChanged="aukcija_bazeDataGrid_SelectionChanged" >
            <datagrid.columns>
                <datagridtextcolumn x:name="aukcijaIDColumn" binding="{Binding Path=auction_ID}" header="Auction ID" width="SizeToHeader" />
                <datagridtextcolumn x:name="artikalNameColumn" binding="{Binding Path=item_name}" header="Item Name" width="SizeToHeader" />
                <datagridtextcolumn x:name="pocetnacijenaColumn" binding="{Binding Path=start_price}" header="Start Price" width="SizeToHeader" />
              <datagridtextcolumn x:name="trenutnacijenaColumn" binding="{Binding Path=current_price}" header="Current Price" width="SizeToHeader" />
            </datagrid.columns>
        </datagrid>
     <Button Content="Login" Height="23" HorizontalAlignment="Left" Margin="331,276,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
     <Button Content="New Auction" Height="23" HorizontalAlignment="Left" Margin="416,276,0,0" Name="button3" VerticalAlignment="Top" Width="75" Click="button3_Click" />
     <Button Content="Bid Price" Height="23" HorizontalAlignment="Left" Margin="12,276,0,0," Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
    </grid>

</window>
C#

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Threading;
using System.Windows.Forms;
using System.Timers;



namespace Aukcija1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        DispatcherTimer timer;
        int interval;
        int step;

        public MainWindow()
        {
            interval = 1001;
            step = 20;
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(interval);
            timer.Start();
            timer.Tick += new EventHandler(timer_Tick);

            DataTable AuctionsTable = new DataTable();
            SqlConnection conn = new SqlConnection(@"datasource=(local);database=Aukcija;integrated security=true;");
            SqlDataAdapter aukcDa = new SqlDataAdapter("select * from auctions", conn);

            aukcDa.Fill(AuctionsTable);
            aukcija_bazeDataGrid.DataContext = AuctionsTable;

        }

        private void InitializeComponent()
        {
            throw new NotImplementedException();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            if (Canvas.GetLeft(button1) > 400)
                timer.Stop();
            step = (step > 1) ? (step -= 1) : 1;
            Canvas.SetLeft(button1, Canvas.GetLeft(button1) + step);
            if (interval > 1)
                timer.Interval = TimeSpan.FromMilliseconds(interval -= 100);
        }

        private void listBox1_SelectionChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = (@"datasource=(local);database=Aukcija;integrated security=true;");
                SqlCommand command = conn.CreateCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "uspPovecajCenuArtiklaZaJedan";
                command.Parameters.AddWithValue("@auction_ID", aukcija_bazeDataGrid.SelectedValue);
                conn.Open();
                command.ExecuteNonQuery();
            }

        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Form1 popup = new Form1();
            popup.ShowDialog();

            popup.Dispose();
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            Form2 popup = new Form2();
            popup.ShowDialog();

            popup.Dispose();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = (@"datasource=(local);database=Aukcija;integrated secutiry=true;");

                SqlCommand command = conn.CreateCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "uspPovecajCenuArtiklaZaJedan";
                command.Parameters.AddWithValue("@auction_ID", 1);
                conn.Open();
                command.ExecuteNonQuery();
            }
        }

        private void loadGrid()
        {
            SqlConnection con = new SqlConnection(@"datasource=(local);database=Aukcija;integrated secutiry=true;");
            SqlDataAdapter ad = new SqlDataAdapter();
            SqlCommand cmd = new SqlCommand();
            con.Open();
            string strQuery = "select * from Auctions";
            cmd.CommandText = strQuery;
            ad.SelectCommand = cmd;
            cmd.Connection = con;
            DataSet ds = new DataSet();
            ad.Fill(ds);
            aukcija_bazeDataGrid.DataContext = ds.Tables[0].DefaultView;
            con.Close();
        }

        private void aukcija_bazeDataGrid_SelectionChanged(object sender, SelectedCellsChangedEventArgs e)
        {

        }

        public UIElement button1 { get; set; }
    }
}
SQL table:

SQL
Auctions (auction_ID, item_name, start_price, current_price).




I got these errors:
The name 'aukcija_bazeDataGrid' does not exist in the current context
The object 'Window' already has a child and cannot add ''. 'Window' can accept only one child. The property 'Content' is set more than once.
Posted
Updated 14-Apr-14 8:06am
v3
Comments
Sergey Alexandrovich Kryukov 14-Apr-14 12:07pm    
In what line?
—SA
Vexy 14-Apr-14 12:13pm    
The object Window.....appears in line 8
The property Content...in line 7
it is in WAML

aukcija_baseDataGrid...in line 47...in C#
Sergey Alexandrovich Kryukov 14-Apr-14 12:25pm    
Why not commenting this line, to show it in the source code?
Most of the code you show is irrelevant to this problem, which is very simple.
Anyway, I answered, please see Solution 1.
—SA
[no name] 14-Apr-14 12:25pm    
You need to go back and re-edit your code. The XAML got lost but I believe it's because you do not have anything in your XAML named "aukcija_bazeDataGrid". At least there was no DataGrid object defined with that name that I could see.
Vexy 14-Apr-14 12:28pm    
I put it System.Windows.Controls.Panel and nothing. Error is still here.

1 solution

Well, yes. You need to set Window.Content to something which can have multiple children, such as System.Windows.Controls.DockPanel, System.Windows.Controls.Grid, System.Windows.Controls.Primitives.TabPanel, derived from System.Windows.Controls.Panel, and a lot more.
Please see: http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.aspx#inheritanceContinued[^].

What you need to understand is the WPF content model: http://msdn.microsoft.com/en-us/library/bb613548%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900