We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How can I change the value of a numericupdown column in other rows?

I have a grid showing DataRows with a DataColumn representing a display position. The display position is represented using a numericupdown cell. I would like to change the display position of all rows when one display position is changed to a proper value. I do the following: private void gridDetailData_CurrentCellChanged(object sender, System.EventArgs e) { if (this.gridDetailData.CurrentCell.ColIndex == this.gridDetailData.SFGridBoundColumns.IndexOf( this.gbcDisplayPosition ) + 1) { this.HandleDisplayPosition( (AppConfiguratorDataSet.DsAppDataViewDefKey.AppDataViewDefRow)this.gridDetailData.GetSelectedRow() ); } } private void HandleDisplayPosition( AppConfiguratorDataSet.DsAppDataViewDefKey.AppDataViewDefRow currentAppDataViewDefRow ) { if (this.gridDetailData.CurrentCell.IsModified) { this.gridDetailData.CurrentCell.ConfirmChanges(); } SortedList rowsSorted = new SortedList(); int index = 1; foreach ( AppConfiguratorDataSet.DsAppDataViewDefKey.AppDataViewDefRow row in this.dsAppDataViewDefKey.AppDataViewDef) { string keySuffix = index.ToString(); if (row == currentAppDataViewDefRow) { keySuffix = "0"; } rowsSorted.Add( row.DisplayPosition.ToString()+"_"+keySuffix.ToString(), row ); index++; } this.gridDetailData.BeginUpdate(); this.gridDetailData.Binder.SuspendBinding(); for (int displayPosition = 1; displayPosition <= rowsSorted.Count; displayPosition++) { AppConfiguratorDataSet.DsAppDataViewDefKey.AppDataViewDefRow row = (AppConfiguratorDataSet.DsAppDataViewDefKey.AppDataViewDefRow)rowsSorted.GetByIndex(displayPosition-1); string key = (string)rowsSorted.GetKey(displayPosition-1); if (row == currentAppDataViewDefRow) { } row.DisplayPosition = displayPosition; string test = string.Empty; } GridCurrentCell cc = this.gridDetailData.CurrentCell; GridStyleInfo style = this.gridDetailData[cc.RowIndex, cc.ColIndex]; if(style.CellType == "NumericUpDown") { this.gridDetailData[cc.RowIndex, cc.ColIndex].Text = cc.Renderer.Control.Text; } this.gridDetailData.Model.ResetVolatileData(); this.gridDetailData.Binder.ResumeBinding(); this.gridDetailData.EndUpdate(); this.gridDetailData.Refresh(); } Regards, Alex

7 Replies

AB Alex Brunner May 5, 2004 11:55 AM UTC

I have forgotten to tell you about the effect I get. The DataRow has the values changes but the cells still show the old values. When saving the values, the values shown by the grid are written to the database. Regards, Alex

AD Administrator Syncfusion Team May 5, 2004 07:06 PM UTC

I don''t really have a clear picture of what you are doing. Is it this line that is not changing the grid value the way you expect it to? this.gridDetailData[cc.RowIndex, cc.ColIndex].Text = cc.Renderer.Control.Text; If so, try using cc.Renderer.ControlText instead of cc.Renderer.Control.Text

AB Alex Brunner May 6, 2004 03:15 AM UTC

Hi Clay I just prepared a sample to show you what I mean. Just try to change the DisplayPosition of the first order by clicking the Up-Button of the NumericUpDown Control. You can see that you have a really suspect behavior. The same DisplayPosition will appear in 2 rows. Now, when you have changed the DisplayPosition of the first row to a value of 7 do the same downwards. Here you can see that everything is numbered as expected. Can you now see, what I tried to describe? Am I doing something wrong or? For me it seems as the NumericUpDown Control is handling the changed value different when increasing than when decreasing the value. Regards, Alex GridNumericUpDownTest_1624.zip

AD Administrator Syncfusion Team May 6, 2004 06:01 AM UTC

If you put this line Console.WriteLine("pos{0} text{1} disp{2}", displayPosition, row.Text, row.DisplayPosition); right ahead of string test = string.Empty; I think you will see why you get 2,2,3,4,... when you change the value in the first row from 1 to 2. So, exactly what to you want to see when you change 1 to 2 in the first row? Test1, 2 Test2, 3 Test3, 4 .... or Test1, 2 Test2, 1 Test3, 3 Test4, 4 ... or something else ??? Are you expecting the rows in the grid to re-arrange themselves somehow? I am not sure this has anything to do with the grid, but with how the SortedList is being used.

AB Alex Brunner May 6, 2004 06:26 AM UTC

Hi Clay The result after the first change should be: Text1 2 Text2 1 Text3 3 Text4 4 It is kind of self re-arranging. If I check with the debugger I can see that in the loop where I set the new DisplayPositions the rows are getting the proper values. Regards, Alex

AD Administrator Syncfusion Team May 6, 2004 06:27 AM UTC

Here is you sample back modified to to make change row 1 to position 2, yield 2,1,3,4,5... GridNumericUpDownTest_7090.zip

AB Alex Brunner May 6, 2004 06:47 AM UTC

Hi Clay It works now! Thank you very much for your great support. Regards, Alex

Live Chat Icon For mobile
Up arrow icon