Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6678269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:13:20+00:00 2026-05-26T04:13:20+00:00

So i have fallen into a problem I am able to update values in

  • 0

So i have fallen into a problem I am able to update values in a data grid when a textbox edits the value of the cell that the datagrid is selected on, this results in a UI update instantly. The pitfal is that i cannot update arbitrary cells that depend on this cell’s value. The data in which the cell/column is bound to changes yet the DataGrid Doesn’t update the depedent cells values. I have a lot of cells so it is very costly to call the DataGrid.Item.Refresh(). I have tried creating a method that just raises an InotifyProperty changed event yet this doesn’t cause an update in the grid. I am at a loss as how to force the GUI to update.

The code for the model cell is below. and the biding code is below it.

public class ModelCell : INotifyPropertyChanged {
    //This is a class that represents a cell that a user clicks on. it contains few items. And should have a reference to the SpreadSheet object
    public String CellName {
        get;
        set;
    }
    public IEnumerable<String> dependents {
        get;
        private set;
    }
    public String Contents {
        get {
            return Host.GetCellContents(CellName);
        }
        set {
            if (value != _contents) {
                IEnumerable<String> tmpDep = Host.SetCellContents(CellName, value);
                try {
                    if (Host.GetCellValue(CellName) is SS.FormulaError) {
                        //Revert the change.
                        Host.SetCellContents(CellName, _contents);
                    } else {
                        _contents = value;
                        NotifyPropertyChanged("Contents");
                        NotifyPropertyChanged("Value");
                        //Next is to notify dependents that we have changed. Since the names will be in the Format of A1
                        this.dependents = tmpDep;
                    }
                } catch (Exception e) {
                    //We got an exception  no change was made to the sheet anyway. 
                    MessageBox.Show(e.Message);
                }
            } else NotifyPropertyChanged("Value");
        }
    }

    public int Row;
    public int Col;
    public override string ToString () {
        return "THis is a test!";
    }


    /// <summary>
    /// Default initialize the empty cell to empty contents. this makes the construction of the objects simpler;
    /// </summary>
    private String _contents = "";

    /// <summary>
    /// This value is contained in the SpreadSheet so it is automatically changed with the Contents.
    /// </summary>
    public String Value {
        get {
            try {
                Object returned = Host.GetCellValue(CellName);
                if (returned is String || returned is Double)
                    return returned.ToString();
                return ((SS.FormulaError)returned).Reason;
            } catch (Exception e) {
                MessageBox.Show("Cell " + this.CellName + " encountered an exception getting the value: " + e.Message);
                return "";
            }
        }
        set {
            //instead assign contents
            NotifyPropertyChanged("Value");
        }
    }
    public SS.Spreadsheet Host {
        set;
        private get;
    }

    /// <summary>
    /// Creates an empty cell with no value or contents with the specified name.
    /// </summary>
    /// <param name="Name">The Name of this cell generally in the format [A-Z][1-99]</param>
    public ModelCell (String Name) {
        this.CellName = Name;
    }
    public ModelCell () {
        //Name will equal the base.ToString()
        this.CellName = base.ToString();
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged (String propertyName) {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler) {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

public MainWindow () {
        InitializeComponent();
        ViewModel = new MainViewModel();
        DataGrid Sheet = null;
        if (this.FindName("Sheet") is DataGrid)
            Sheet = (DataGrid)this.FindName("Sheet");
        if (Sheet == null)//Exit
            this.Close();
        IValueConverter converter = new ModelCellConverter();
        Binding bind;
        for (int i = 0; i < 26; i++) {
            DataGridColumn col = new DataGridTextColumn();
            col.Header = (char)('A' + i);
            col.IsReadOnly = true;
            col.Width = new DataGridLength(60);
            col.CanUserSort = false;
            //bind = new Binding(new String((char)('A' + i), 1));
            bind = new Binding("indexAbleArr[" + i + "].Value");
            //bind.Converter = new IdentityConverter();
            bind.Mode = BindingMode.OneWay;
            ((DataGridTextColumn)col).Binding = bind;
            Sheet.Columns.Add(col);
        }
        Sheet.ItemsSource = ViewModel.Rows;

        //Current cell display
        Label lab = null;
        if (this.FindName("CurCell") is Label) {
            lab = (Label)this.FindName("CurCell");
            bind = new Binding("ActiveCell.CellName");
            bind.Source = ViewModel;
            bind.NotifyOnSourceUpdated = true;
            lab.SetBinding(Label.ContentProperty, bind);
        } //Don't bind the label if i cant find it
        if (this.FindName("ValueBox") is Label) {
            lab = (Label)this.FindName("ValueBox");
            bind = new Binding("ActiveCell");
            bind.Source = ViewModel;
            bind.Converter = converter;
            bind.NotifyOnSourceUpdated = true;
            lab.SetBinding(Label.ContentProperty, bind);
        }
        TextBox content = null;
        if (this.FindName("Content") is TextBox) {
            content = (TextBox)this.FindName("Content");
            bind = new Binding("ActiveCell.Contents");
            bind.Source = ViewModel;
            bind.Mode = BindingMode.TwoWay;
            bind.NotifyOnSourceUpdated = true;
            content.SetBinding(TextBox.TextProperty, bind);
        }
        ViewModel.ActiveCell = ViewModel.Rows[0].indexAbleArr[0];
 }

I am using XAML To specify the Layout but no binding is done via XAML so nothing noteworthy is in my XAML code. Rows is a Object that contains an array of model cells (indexAbleArray) for the purposes of binding. It also precreates the 26 needed modelcells for the binding to not throw a million null pointer exceptions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:13:21+00:00Added an answer on May 26, 2026 at 4:13 am

    I think the problem is your portion of index based columns indexAbleArr[" + i + "] in the binding Path of your DataGridTextColumns. They are not participating in the property change notifications.

    As BalamBalam suggested make that array into an ObservableCollection or you should be raising a property changed notification at row level for property “indexAbleArr” when any cell int that array changes it Value.

    Both to me are actually incomplete designs. 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have transactional replication running between two databases. I fear they have fallen slightly
I've been trying to implement a function that needs partial template specializations and fallen
I've fallen into a situation where it would be advantageous to store both ascii
I have a project that I thought was going to be relatively easy, but
I am starting out on a new project and have fallen in love with
I have implemented a test Client / Server that implements UserName message authentication over
We have slony replication set up, and the replication on the slave has fallen
Have a xml string, goal is to replace an xml element value to a
Here is what I want to do: Have a windows service that hosts a
hejdig. In Aspnetmvc2 I have a model object that I send to a View.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.