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

  • Home
  • SEARCH
  • 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 8770243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:31:25+00:00 2026-06-13T17:31:25+00:00

I have a datagridview that has been populated from a datatable using the datasource

  • 0

I have a datagridview that has been populated from a datatable using the datasource property. I need to change the value of a cell without affecting the database. So far I could only find that I have to first change the databound item but no information about how to do that. Besides, I don’t want to change the databound item.

The reason for wanting to do this is that I have a list of records with a start and end time and there is a computed field that gives the difference in seconds. I need to change the value of the computed field and change the height of the row accordingly, that is, the height of each row is proportional to the duration it represents. Changes are done from a text box which increments quickly if the “increase” button is kept down and therefore I cannot change the database with each increment. Rather I would change the value in the table frequently and update the database once the increments stops.

I have tried updating the datagridview directly using this code:

dgvTasks.Rows(SelectedRowIndex).Cells(5).Value = DateAdd(DateInterval.Minute, DateDiff(DateInterval.Minute, CDate("00:00:00"), CDate(txtDuration.Text & ":00")), dgvTasks.Rows(SelectedRowIndex).Cells(4).Value)

But receive the error:

System.Data.ReadOnlyException: Column ‘Column1’ is read only.

I also tried updating the datatable, and allowing the calculated column to update:

dtblTasks.Rows(SelectedRowIndex)(5) = DateAdd(DateInterval.Minute, DateDiff(DateInterval.Minute, CDate("00:00:00"), CDate(txtDuration.Text & ":00")), dtblTasks.Rows(SelectedRowIndex)(4)) 
dgvTasks.DataSource = dtblTasks

But the calculated value doesn’t change.

I am also providing an additional calculated value (in the SQL) where I find the difference in minutes and the append a string literal to that:

( CAST ( DATEDIFF(MINUTE, Tasks.TaskStart, Tasks.TaskEnd) AS NVARCHAR(10) ) + ' mins') AS TaskDurationString

Is there a way to detach the grid from the datasource but still keep the data visible in the datagrid and manipulate it (without affecting the databound object)? Or perhaps some other approach to this problem?

  • 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-06-13T17:31:26+00:00Added an answer on June 13, 2026 at 5:31 pm

    Updating the calculated column in the DataTable should work – I’ve just tried it, and both when I edit one of the values that are part of the calculated value, and when I change the value in code, that column is recalculated and the grid UI updates.

    One thing to check is that you are calculating the value correctly. You should be using the DataTable~ column [Expression` property]1. Something like this:

    dt.Columns["FullName"].Expression = "FirstName + LastName";
    

    Since it appears that you don’t actually need to bind any of these values to the DataTable or persist them to the database, one possible solution is to do all of this in an unbound DataGridView calculation column.

    To do that add a column using the designer, then in the cell validating event have something like this:

    void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
    {
        dataGridView1.Rows[e.RowIndex].Cells["TargetColumn"].Value = dataGridView1.Rows[e.RowIndex].Cells["FirstName"].Value.ToString() + dataGridView1.Rows[e.RowIndex].Cells["LastName"].Value.ToString();
        dataGridView1.Rows[e.RowIndex].Height = dataGridView1.Rows[e.RowIndex].Cells["LastName"].Value.ToString().Length + dataGridView1.Rows[e.RowIndex].Cells["FullName"].Value.ToString().Length;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dynamically created DataGridView that has a valid DataSource with one row
I have a DataGridView bound to a DataTable that has 1+16 columns defined as
I have a DataGridView that is bound to a DataTable, it has a column
I have a DataGridView that has a class as its DataSource. The class contains
I have created a binded DataGridView that has one single column. I want to
I have a Winforms app that has a DataGridView that is databound at runtime.
I have a DataGridView in a Winforms app that has about 1000 rows (unbound)
I have a DataGridView that's bound to a DataSet. It has columns DateCreated, Weight,
I have: MenuStrip that has File>Save that saves DataGridView values to a database DataGridView
I have a WindowsForm that has a DataGridView that shows output of my app.

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.