Click here to Skip to main content
15,561,958 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: DropShadowEffect Above & Below Pin
Richard Deeming30-Nov-22 22:30
mveRichard Deeming30-Nov-22 22:30 
QuestionWhat's Wrong With This Style? Pin
Kevin Marois21-Nov-22 10:57
professionalKevin Marois21-Nov-22 10:57 
AnswerRe: What's Wrong With This Style? Pin
Gerry Schmitz21-Nov-22 11:17
mveGerry Schmitz21-Nov-22 11:17 
GeneralRe: What's Wrong With This Style? Pin
Kevin Marois21-Nov-22 12:44
professionalKevin Marois21-Nov-22 12:44 
QuestionStyle Question Pin
Kevin Marois20-Nov-22 11:30
professionalKevin Marois20-Nov-22 11:30 
AnswerRe: Style Question Pin
Richard Deeming20-Nov-22 23:37
mveRichard Deeming20-Nov-22 23:37 
GeneralRe: Style Question Pin
Kevin Marois21-Nov-22 9:05
professionalKevin Marois21-Nov-22 9:05 
Questionediting a WPF DataGrid Pin
pitwi13-Nov-22 10:08
pitwi13-Nov-22 10:08 
Hi!
I've searched for a couple of hours here and in other forums and at GitHub but couldn't find an answer.
I have a XML file and can read it in a DataTable and show that in a DataGrid. But I want to edit cells/values in the DataGrid and write the corrected values back to the XML file. It's easy for me to write the corrections to the DataTable and back to the XML file but how can I do the edit in the DataGrid ???
What I have so far with VisualStudio 2022:

using ...

namespace Gewicht
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public string[] dbFile = { @"H:\Daten\C#WPF\Gewicht\GewichtDaten.xml", @"H:\Daten\C#WPF\Gewicht\GewichtDaten.xsd" };
        public DataTable dbDataTbl = new DataTable();

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (!System.IO.File.Exists(dbFile[0]) | !System.IO.File.Exists(dbFile[1]))
                {
                SystemSounds.Beep.Play();
                MessageBox.Show("Die Datei" + Environment.NewLine + "   " + dbFile[0] + Environment.NewLine + "und/oder" + Environment.NewLine + "   " + dbFile[1] + Environment.NewLine + "fehlt." + Environment.NewLine + "Das Programm wird beendet.", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(0);
            }
            DataGrid1.CanUserAddRows = false;
            DataGrid1.CanUserDeleteRows = false;
            OpenData();
        }


        private void DataGrid1_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            // edit
            // ... ???????????????????????? ...
        }


        private void OpenData()
        {
            // open data

            dbDataTbl.Columns.Clear();
            dbDataTbl.Rows.Clear();
            dbDataTbl = new DataTable("ich");
            dbDataTbl.ReadXmlSchema(dbFile[1]);
            dbDataTbl.ReadXml(dbFile[0]);
            // DataGrid
            DataSet dataSet = new DataSet();
            dataSet.ReadXml(dbFile[0]);
            DataView dataView = new DataView(dataSet.Tables[0]);
            DataGrid1.ItemsSource = dataView;
            // format columns
            Style style = new Style();               // creates object of style class   
            style.TargetType = typeof(DataGridCell); // sets target type as DataGrid cell
            Setter setter = new Setter();            // create objects of setter class   
            setter.Property = DataGridCell.ForegroundProperty;
            setter.Value = Brushes.LightGray;
            style.Setters.Add(setter);
            DataGrid1.Columns[0].CellStyle = style;
            style = new Style();
            setter = new Setter();
            setter.Property = DataGridCell.HorizontalContentAlignmentProperty;
            setter.Value = HorizontalAlignment.Right;
            DataGrid1.Columns[2].CellStyle = style;
        }

    }
}


What I also want:
- Data column 0 should be gray (done) and the values right aligned.
- Data column 2 should be right aligned and with number format "##0.0".

Thanks
AnswerRe: editing a WPF DataGrid Pin
Gerry Schmitz15-Nov-22 8:38
mveGerry Schmitz15-Nov-22 8:38 
QuestionCan I see the bounding box around WPF controls at runtime ? Pin
Maximilien27-Oct-22 4:16
Maximilien27-Oct-22 4:16 
AnswerRe: Can I see the bounding box around WPF controls at runtime ? Pin
Richard Deeming27-Oct-22 5:05
mveRichard Deeming27-Oct-22 5:05 
QuestionCustom drawing ToggleButton when checked Pin
Maximilien17-Oct-22 10:12
Maximilien17-Oct-22 10:12 
AnswerRe: Custom drawing ToggleButton when checked Pin
Gerry Schmitz17-Oct-22 11:11
mveGerry Schmitz17-Oct-22 11:11 
GeneralRe: Custom drawing ToggleButton when checked Pin
Maximilien24-Oct-22 3:48
Maximilien24-Oct-22 3:48 
QuestionReferencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 3:24
Maximilien5-Oct-22 3:24 
AnswerRe: Referencing DrawingImage in a binding. Pin
Richard Deeming5-Oct-22 6:29
mveRichard Deeming5-Oct-22 6:29 
GeneralRe: Referencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 8:14
Maximilien5-Oct-22 8:14 
GeneralRe: Referencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 8:55
Maximilien5-Oct-22 8:55 
QuestionDesign Question Pin
Kevin Marois2-Oct-22 12:13
professionalKevin Marois2-Oct-22 12:13 
AnswerRe: Design Question Pin
Gerry Schmitz2-Oct-22 16:47
mveGerry Schmitz2-Oct-22 16:47 
QuestionLooking for a WPF control. Pin
Maximilien22-Sep-22 9:40
Maximilien22-Sep-22 9:40 
AnswerRe: Looking for a WPF control. Pin
Richard Deeming22-Sep-22 22:39
mveRichard Deeming22-Sep-22 22:39 
GeneralRe: Looking for a WPF control. Pin
Maximilien23-Sep-22 2:33
Maximilien23-Sep-22 2:33 
GeneralRe: Looking for a WPF control. Pin
Maximilien23-Sep-22 2:54
Maximilien23-Sep-22 2:54 
QuestionWeird behavior with contextual menu not rendering properly. Pin
Maximilien21-Sep-22 8:00
Maximilien21-Sep-22 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.