WPF DataGridNumericUpDownColumn set value from DataTable

ساخت وبلاگ
چکیده : Vote count: 0 I'm new to WPF and I'm t... با عنوان : WPF DataGridNumericUpDownColumn set value from DataTable بخوانید :

Vote count: 0

I'm new to WPF and I'm trying to set the value the DataGrid Column "DataGridNumericUpDownColumn" from a Database. I get the data as DataTable and bind it to the DataGrid.

That's the table I fetch my items from.

CREATE TABLE Items
(
    ITEM varchar(64),
    PART_NUMBER varchar(64),
    TYPE varchar(64),
    MANUFACTURER varchar(64),
    PRICE decimal(32,2) NOT NULL,
    PRIMARY KEY(ITEM, PART_NUMBER, TYPE, MANUFACTURER),
    FOREIGN KEY (MANUFACTURER, TYPE)
    REFERENCES ManufacturerType(MANUFACTURER,TYPE)
        ON UPDATE CASCADE
        ON DELETE CASCADE
);

C# Code

private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
{
    //////////////////////////////////////////////////////////////////////////////////////////
    // ITEMS TABLE                                                                          //
    //////////////////////////////////////////////////////////////////////////////////////////
    StringBuilder command = new StringBuilder();
    command.Append("SELECT MIN(ii.IMAGE_PATH) AS IMAGE_PATH, MAX(i.ITEM) AS ITEM, i.PART_NUMBER AS PART_NUMBER, ");
    command.Append("MAX(i.TYPE) AS TYPE, MAX(i.Manufacturer) AS MANUFACTURER, i.PRICE FROM ");
    command.Append("Items i ");
    command.Append("LEFT JOIN Item_Images ii ON i.PART_NUMBER = ii.PART_NUMBER ");
    command.Append("GROUP BY i.PART_NUMBER, i.ITEM");
    //SETUP COLUMNS FOR ITEMS TABLE
    DataTable dt = mysql_database.queryDataFromDatabaseWithSQLCommand(command.ToString());
    dgItems.Columns.Add(createImageColumn("IMAGE", new Binding("IMAGE_PATH"), new Size(32, 32)));
    foreach (DataColumn dcol in dt.Columns)
    {
        if (dcol.ColumnName.ToUpper() == "PRICE")
        { 
            dgItems.Columns.Add(createDataGridNumericUpDownColumn(dcol.ColumnName.ToUpper(), "C"));

        }
        else
        {
            DataGridTextColumn dgc = new DataGridTextColumn();
            dgc.Header = dcol.ColumnName.ToUpper();
            dgc.Binding = new Binding(dcol.ColumnName.ToUpper());
            dgc.IsReadOnly = true;
            dgItems.Columns.Add(dgc);
        }
    }
    dgItems.ItemsSource = dt.DefaultView;
}

The code for creating the DataGridNumericUpDownColumn

public DataGridNumericUpDownColumn createDataGridNumericUpDownColumn(string header, string format)
{
    DataGridNumericUpDownColumn dtemp = new DataGridNumericUpDownColumn();
    dtemp.Minimum = 0.00;
    dtemp.Binding = new Binding("{" + header + "}");
    dtemp.StringFormat = format;
    dtemp.Header = header;

    return dtemp;
}

However when I run my application, the field with the numericupdown is empty. The value will not be set from the DataTable.

Image of the running tool

This is what's stored in the database.

Image of the data row in the database

I'm out of ideas how to get this working. Any help is appreciated! Thanks!

asked 50 secs ago
Andreas Reitberger

back soft...
ما را در سایت back soft دنبال می کنید

نویسنده : استخدام کار بازدید : 29 تاريخ : يکشنبه 24 تير 1397 ساعت: 16:29