简体   繁体   中英

.net Can't edit values in Datagridview on Runtime

I created an unbound DatagridView which rows are input manually during runtime and are supposed to be editable.

Using the command DataGridView->Rows->Add(string,..) it creates the row properly but it doesn't allow me to edit the values manually, even though it's not on "Read Only".

The code used for input:


    private: System::Void ButtomSave_Click(System::Object^  sender, System::EventArgs^  e) {     

  String^ folderName;
/*DataGridViewComboBoxColumn^ cmbCol = gcnew DataGridViewComboBoxColumn;
cmbCol->HeaderText = "Sagital/Coronal";
cmbCol->Items->Add("-");
cmbCol->Items->Add("Sagital");
cmbCol->Items->Add("Coronal");
dataGridView1->Columns->Add(cmbCol);*/
  FolderBrowserDialog^ folderBrowserDialog1 = gcnew FolderBrowserDialog;
  folderBrowserDialog1->Description="Select the folder containing the image sequences folder";
  // Do not allow the user to create new files via the FolderBrowserDialog.
  folderBrowserDialog1->ShowNewFolderButton = false;  
    // Default to the My Documents folder.
  folderBrowserDialog1->RootFolder = Environment::SpecialFolder::Personal;
  if ( folderBrowserDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
    {
      folderName = folderBrowserDialog1->SelectedPath;
      array<String^>^subdirectoryEntries = Directory::GetDirectories( folderName );
   DataGridViewRow row;
      System::Collections::IEnumerator^ myEnum = subdirectoryEntries->GetEnumerator();
      while ( myEnum->MoveNext()){

        dataGridView1->Rows->Add(myEnum->Current,"Sagital");  

      }
    }
}

My application is written using Windows Forms in C++ language.

thanks in advance

Problem solved. I had to set the whole datagridview as "Read Only" (I'm familiar with Qt).

To clarify my own question, to make the datagridview cells editable right click on it, then properties->behaviour section->ReadOnly->False (it's True by default).

Thanks for the replies

Can you actually add a string to the row? Wouldn't you have to create a Row object to add to the collection?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM