2011-01-28 47 views
1

我創建了一個未綁定的DatagridView,這些行在運行期間手動輸入,並且應該是可編輯的。.net無法在運行時編輯Datagridview中的值

使用命令DataGridView-> Rows-> Add(string,..)它會正確創建行,但它不允許我手動編輯值,即使它不在「只讀」上。

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"); 

     } 
    } 
} 

我的應用程序是用C++語言編寫的Windows窗體。

在此先感謝

回答

1

問題已解決。我不得不將整個datagridview設置爲「只讀」(我熟悉Qt)。

爲了說明我自己的問題,爲了讓datagridview單元可以右鍵單擊它,然後properties-> behavior section-> ReadOnly-> False(默認情況下爲True)。

感謝您的答覆

0

你真的可以添加一個字符串的行嗎?你不需要創建一個Row對象來添加到集合中嗎?

+0

我敢肯定,Rows-> Add()方法將創建一個新的行與所提供的列數據。 http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx – 2011-01-28 19:43:04