.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

DataTable Bound to DatagridView DataRowState.Modified not getting change on first row

Posted By:      Posted Date: October 19, 2010    Points: 0   Category :Windows Application

Updating the first record listed in my DataGridView that is bound to my DataTable . When I run Save process I run through this line of code to get all records that have been modified:


If I have changed the first record in my DataGridView my modifiedRows DataTable is Null. If I change any of the following records they are in my modifiedRows DataTable .
I have tried changing other records in my DataGridView first and then changing the first record then running the Save process and still....other records are there and the first record is not.....

Also....I checked the unitDataDT and it has the change. I sorted the datagridview to try and update a different record and it still did not add the change to the modifiedRows Datatable....so it seems to not work for the first record listed in the DataGridView.

Any ideas?

View Complete Post

More Related Resource Links

dropdownlist bound to sqldatasource adds items instead of replacing on change



I have a series of dropdownlists on webform in ASP 4.0. The first drop down is filled upon load, and then when a user selects a value from that list, it populates the second dropdown. To accomplish this, I have a SQLdatasource with a parametersource of the first drop-down list control. This works great, except when a user changes their selection from the first drop down. It performs the query, but then adds the list of items to the ones that were already there from the previous selection, instead of replacing it with the new data. Here is the code:

 <asp:DropDownList ID="ddlMajor" runat="server" DataMember="DefaultView" 
      DataSourceID="SqlDataSource1" DataTextField="majortext" 
      DataValueField="majorkey" AppendDataBoundItems="True" AutoPostBack="True">
         <asp:ListItem Value="0">Select Major</asp:ListItem>
<asp:DropDownList ID="ddlReq" runat="server" DataMember="DefaultView" 
      DataSourceID="SqlDataSource2" DataTextField="req" DataValueField="admreqkey" 
            AppendDataBoundItems="True" AutoPostBack="True">
                <asp:ListItem Value="0">Sel

DataGridView>Edit Columns> Column Read Only property is unwilling to change

Hello, I am facing the following mystery: When changing the read only property of a column to false and reopening the "edit columns" window, it mysteriously turns back to true. Even when closing the designer and changing it in the designer code, the resulting execution does not allow edit, as well as when re-opening the designer you see true again.             this.numberDataGridViewTextBoxColumn1.DataPropertyName = "Number";             this.numberDataGridViewTextBoxColumn1.HeaderText = "Number";             this.numberDataGridViewTextBoxColumn1.Name = "numberDataGridViewTextBoxColumn1";             this.numberDataGridViewTextBoxColumn1.ReadOnly = true;//False is required We thought it might be related to data binding. rebinding the grid did not help as well. The is no other place in the code where it changes. Please advice, Thanks

cannot get the crystalreport1.rpt to recognize the change made to the datatable, help..

added a dataset.xsd file, kept a datatable in it, nothing elsebinded the dataset as a datasource for the srystalreport1.rptnow my aim is to, make the dataset populated by code to appear in the report (note the gridview does recongize the change, also note i have tried using the init page method but no luck)heres the code behind.        DataSet1 ds = new DataSet1();        //DataTable dt;        DataRow dr;        DataColumn idCoulumn;        DataColumn nameCoulumn;        int i = 0;        //dt = new DataTable();        idCoulumn = new DataColumn("ID", Type.GetType("System.Int32"));        nameCoulumn = new DataColumn("Name", Type.GetType("System.String"));        ds.DataTable1.Columns.Add(idCoulumn);        ds.DataTable1.Columns.Add(nameCoulumn);        dr = ds.DataTable1.NewRow();        dr["ID"] = 1;        dr["Name"] = "Name1";        ds.DataTable1.Rows.Add(dr);        dr = ds.DataTable1.NewRow();   &nb

How to Change the Color of Link Label which is a Datagridview Column on a Row Selection?

Hi All I have a Link label as one of the column of Datagridview & also my SelectionBackColor set to Blue. Is there any way that i can change the link label color on a particular row selection as now my selectionbackcolor & link label color is matching...I am unable to the contents of that link label column. Should i do this on design level or in code level? Pls Help

datatable bind to datagridview

i have a datatable with 3000 records, when i bind to datagridview, it takes a long time to display record, how to improve this so that the datagridview can be displayed faster

Programatically change a TwoWay bound control, change wasn't commited.



I had a TextBox bound to a single DataColumn with TwoWay mode,
then checked if it works by manually changing the text.

But when I programmatically changed the value of TextBox.text, the DataColumn wasn't changed.

Here is a snippet, anything wrong?

    <TextBox Name="tbName" Text="{Binding Path=DataColumn1,Mode=TwoWay}"/>
    <Button Name="Change" Click="Change_Click" Content<

List.aspx:datagridview Change the links to parent table from Details to list


The List Page display  child Entity using the  gridview each row will have  link to the  parent 


How can I change the link so it shows the parent but in list view(using list.aspx) not detailes (detailes.aspx)view






I checked the



List.aspx:datagridview Change the links to parent table from Details to list


The List Page displays a child Entity using the  gridview, each row  has a to link to the  parent in detailes view how can I change to list view .

use list.aspx?parent=32 not detailes.aspx ?parentId=32

DataGridView - Event triggered when row change while SelectionMode is DataGridViewSelectionMode.Full



I have a data grid view with SelectionMode == DataGridViewSelectionMode.FullRowSelect.  I was wondering if there is an event triggered when the row selected is changed?  I have tried SelectionChanged, CurrentCellChanged, RowEnter, CellClick but none of these events get triggered when the row selected is changed while SelectionMode == DataGridViewSelectionMode.FullRowSelect.  

change the datagridview layout


Dear all,

In my project, I am using some third-party datagrid and also datagridview. How to convert below code to be using in datagridview??

(1) change the width of the columns

(2) align the cells

(3) Columns format

foreach(UltraGridColumn temp in dtg.DisplayLayout.Bands[i].Columns)

                    if (temp.DataType == typeof(DateTime))
                        temp.Format = "yyyy-MM-dd";
                        temp.Width = 90;
                    else if (temp.DataType == typeof(string))

Change the created and modified values of a file in SharePoint


I am trying to import a bunch of files into SharePoint from an old collaboration system we are getting rid of. The problem I am facing is the file information must be retained. For example, if the file was created 12/14/2007 by Joe, and then modified 4/10/2009 by Sue, I need to make sure that information is set in SharePoint when I add the file.
It looks like the needed properties in SPFile are "get" only.
I also tried to use a hashtable to try and force those values upon the file upload as shown in the code below, but that didn't work either.

        private static void UploadFile(string srcUrl, string destUrl)
                using (SPWeb site = new SPSite(destUrl).OpenWeb())
                    //## Put the file into a filestream
                    FileStream fStream = File.OpenRead(srcUrl);
                    byte[] contents = new byte[fStream.Length];
                    fStream.Read(contents, 0, (int)fStream.Length);
                    //## A hashtable for the file metadata
                    Hashtable metadata = new Hashtable();
                    metadata.Add("ModifiedBy", "Joe Blow");

Problems refreshing DataGridView (bound to a BindingList)



I have bound a DataGridView to a BindingList<MyEntity>. MyEntity has some properties that affect other property values. Let's say, because it's true, it has a DisplayCurrency property that controls what currency is returned in various Amount properties. I show a list of available currencies, and when the selected currency changes I do something like this:

var list = (BindingList<MyEntity>)grid.DataSource;

foreach (var entity in list)

 entity.DisplayCurrency = selectedDisplayCurrency;


AFAIU, ResetBindings() is a way for me to notify the binding list that I've modified its content, and the list will then in turn notify the gridview by firing off an event. And it works fine; all the amounts in the grid are updated.

It's all very wonderful, except for the fact that it seems to behave as if I had removed the datasource and re-assigned it...

  • I lose the sort state
  • It scrolls to the top
  • I lose the selected item
  • ...

So I guess my question is: Is there any way I can get the DataGridView to just reflect the changed values

Custom Editing Behavior for DataGridView TextBox Columns

For various reasons I'm using a DataGridView instead of a ListView, and while configuring the DataGridView to look like a ListView wasn't much of a problem, there's one thing that got on my nerves, which is the behavior of textbox cells in edit mode: It is much too easy to leave the edit mode accidentally, simply by pressing the cursor keys at the wrong time. For example when the text caret is positioned behind the last character of the textbox cell content, and you press the right arrow key

AutoCompleteStringCollection for text box in DataGridView 2.0

I have been searching for a way to have autocomplete in a DataGridTextBox
object. There does not appear to be an obvious way to do this like you would
for a TextBox outside of a grid using the AutoCompleteCustomSource. Any
thoughts on how I can add this collection? :)

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

DataTable - Load from IDataReader - CreateDataReader - ReadXml WriteXml - Free ADO.NET Tutorials

The DataTable in ADO.NET 2.0 has been seriously beefed up and I absolutely love it. Not everything we consume deals with multiple resultsets and requires the ever popular DataSet. With the cool new features in the ADO.NET 2.0 DataTable, we can get many of the cool features in the DataSet without all the extra baggage and memory footprint particular to multiple resultsets.

Load DataTable from IDataReader

How to Localize Windows Forms and Change the Language at Runtime

Localization is the process of customizing your application to a particular language, culture or locale. Visual Studio provides support for localizing Windows Forms with much ease. In this article, we will see how to localize windows forms and give the user the ability to change to his preferred language at runtime.
When you run a localized application, the appearance is determined by two culture values. The UICulture property is used to specify which resource files will be loaded for the form. The Culture property, on the other hand, determines how strings such as dates, numerals, and currency amounts are formatted.
Let us see the steps required to create a localized form. You can then expand this example and adopt the same approach for the rest of the forms in your project
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend