By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,602 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,602 IT Pros & Developers. It's quick & easy.

Datagrid view problem please help me its urgent

P: 14
i am getting an exception while end editing the 1st column 1st row of the cell(1,1) it is a combobox cell of datagridview everytime it showing following exception only on endedit

dont know why can anybody help me plz

"Operation not valid because it results in reentrant call to the SetCurrentCellAddress core function"

Expand|Select|Wrap|Line Numbers
  1. ArrayList taName = (ArrayList)_responseparser.tableEnum[r];
  2. ArrayList taValue = (ArrayList)_responseparser.tableValue[r];
  3. DataGridViewComboBoxCell comboCell = new DataGridViewComboBoxCell();
  4. for (int s = 0; s < taName.Count; s++)
  5. {
  6.     comboCell.Items.Add(taName[s]);
  7. }
  8. dataGridView1[1, r] = comboCell;
  9. id = (ushort)_responseparser.tableId[r];
  10. data = CommMngr.SelectedUnit.Modbus.GetParameter(id);
  11. for (int m = 0; m < taName.Count; m++)
  12. {
  13.     if (data != null)
  14.     {
  15.         if (data[0] == Convert.ToInt32(taValue[m]))
  16.         {
  17.             dataGridView1[1, r].Value = (string)taName[m];
  18.             break;
  19.         }
  20.     }
  21. }
  22.  
the bolded line arising the exception EDIT: that would be line 8

can anyone help me plz...............
Jul 17 '08 #1
Share this Question
Share on Google+
6 Replies


Curtis Rutland
Expert 2.5K+
P: 3,256
Please use the [code] tags when posting code snippets. This makes it easier for our experts to read and understand your code, and the easier they can read it, the easier they can help with your problem. You can insert them by clicking the # button in the editor. Please read the Posting Guidelines for more information.

MODERATOR
Jul 17 '08 #2

Plater
Expert 5K+
P: 7,872
What is this _responseparser.tableId[r]; buisness?
What type of object is _responseparser?
And the tableid[r] is?
Jul 17 '08 #3

P: 14
What is this _responseparser.tableId[r]; buisness?
What type of object is _responseparser?
And the tableid[r] is?
_responseparser is a class object
and tableid[r]is a property from that class
Jul 18 '08 #4

P: 14
Please help me in this Exception
Expand|Select|Wrap|Line Numbers
  1. else if (_responseparser.tableType[r].ToString() == NONENUMERICAL)
  2.             {
  3.                 dataGridView1.Rows[r].Cells[0].Value = _responseparser.tableName[r];
  4.                 int valueCount = _responseparser.tableValue.Count;
  5.                 if (valueCount != 0)
  6.                 {
  7.                     ArrayList taName = (ArrayList)_responseparser.tableEnum[r];
  8.                     ArrayList taValue = (ArrayList)_responseparser.tableValue[r];
  9.                     DataGridViewComboBoxCell comboCell = new DataGridViewComboBoxCell();
  10.                     for (int s = 0; s < taName.Count; s++)
  11.                     {
  12.                         comboCell.Items.Add(taName[s]);
  13.                     }
  14.                     dataGridView1[1, r] = comboCell;
  15.                     id = (ushort)_responseparser.tableId[r];
  16.                     data = CommMngr.SelectedUnit.Modbus.GetParameter(id);
  17.                     for (int m = 0; m < taName.Count; m++)
  18.                     {
  19.                         if (data != null)
  20.                         {
  21.                             if (data[0] == Convert.ToInt32(taValue[m]))
  22.                             {
  23.                                 dataGridView1[1, r].Value = (string)taName[m];
  24.                                 break;
  25.                             }
  26.                         }
  27.                     }
  28.                 }
  29.             }
exception is at bolded line

"Operation not valid because it results in reentrant call to the SetCurrentCellAddressCore Function"

only on editing the cell[1,1] with cell end edit
Jul 22 '08 #5

Plater
Expert 5K+
P: 7,872
It sounds like you have a funcion that gets called when the data in a cell changes, and in that function you are setting one of the cells. I think it is sync-locking the cells implicitly and it's telling you what you are trying to do would break that sync lock.
(Like if you are using a foreach loop and try to remove something from the collection you are looping through, it gets mad)
Jul 22 '08 #6

P: 14
It sounds like you have a funcion that gets called when the data in a cell changes, and in that function you are setting one of the cells. I think it is sync-locking the cells implicitly and it's telling you what you are trying to do would break that sync lock.
(Like if you are using a foreach loop and try to remove something from the collection you are looping through, it gets mad)
Expand|Select|Wrap|Line Numbers
  1. private void DataColumnAdd(int r)
  2.         {
  3.             ushort id, scalefactor;
  4.             ushort[] data = new ushort[8];
  5.             double sValue;
  6.             if (_responseparser.tableType[r].ToString() == NUMERICAL)
  7.             {
  8.                 dataGridView1.Rows[r].Cells[0].Value = _responseparser.tableName[r];
  9.                 id = (ushort)_responseparser.tableId[r];
  10.                 data = CommMngr.SelectedUnit.Modbus.GetParameter(id);
  11.                 if (data != null)
  12.                 {
  13.                     //dataGridView1.Rows[r].Cells[1].Value = data[0];
  14.                     scalefactor = ushort.Parse(_responseparser.tableScaleFactor[r].ToString());
  15.                     decimal dispValue = ((decimal)data[0] / (decimal)scalefactor);
  16.                     string decimalAdjusted = dispValue.ToString("N1");
  17.                     bool disValue = double.TryParse(decimalAdjusted, out sValue);
  18.                     if (disValue)
  19.                     {
  20.                         dataGridView1.Rows[r].Cells[1].Value = decimalAdjusted;
  21.                     }
  22.                 }
  23.                 else
  24.                 {
  25.                     dataGridView1.Rows[r].Cells[1].Value = "null";
  26.                 }
  27.                 dataGridView1.Rows[r].Cells[2].Value = _responseparser.tableUnit[r];
  28.             }
  29.             else if (_responseparser.tableType[r].ToString() == NONENUMERICAL)
  30.             {
  31.                 dataGridView1.Rows[r].Cells[0].Value = _responseparser.tableName[r];
  32.                 int valueCount = _responseparser.tableValue.Count;
  33.                 if (valueCount != 0)
  34.                 {
  35.                     ArrayList taName = (ArrayList)_responseparser.tableEnum[r];
  36.                     ArrayList taValue = (ArrayList)_responseparser.tableValue[r];
  37.                     DataGridViewComboBoxCell comboCell = new DataGridViewComboBoxCell();
  38.                     for (int s = 0; s < taName.Count; s++)
  39.                     {
  40.                         comboCell.Items.Add(taName[s]);
  41.                     }
  42.                     dataGridView1[1, r] = comboCell;
  43.                     id = (ushort)_responseparser.tableId[r];
  44.                     data = CommMngr.SelectedUnit.Modbus.GetParameter(id);
  45.                     for (int m = 0; m < taName.Count; m++)
  46.                     {
  47.                         if (data != null)
  48.                         {
  49.                             if (data[0] == Convert.ToInt32(taValue[m]))
  50.                             {
  51.                                 dataGridView1[1, r].Value = (string)taName[m];
  52.                                 break;
  53.                             }
  54.                         }
  55.                     }
  56.                 }
  57.             }
  58.             else if (_responseparser.tableType[r].ToString() == EMPTYDATASET)
  59.             {
  60.                 dataGridView1.Rows[r].Cells[0].Value = "Method";
  61.                 dataGridView1.Rows[r].Cells[0].Style.BackColor = Color.LightGray;
  62.                 dataGridView1.Rows[r].Cells[1].ReadOnly = true;
  63.                 dataGridView1.Rows[r].Cells[1].Style.BackColor = Color.LightGray;
  64.                 dataGridView1.Rows[r].Cells[1].Value = _responseparser.tableName[r];
  65.             }
  66.         }
this is the that function initially i populate a datagridview and then upon editing again i am populating datagridview, i understand ur statements,

but if i am changing the collection means it should happen when i am editing all the comboboxcells but i am getting that exception whenever i am editing comboboxcell at [1,1] everytime thats what i get confused

could u tell me where i should make changes?
Jul 23 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.