can't figure out how to add items to a datagridviewI know how to add rows to a datagridview in VB and C# but I can't seem to figure out how to do it in C++. I have a textbox that the user fills in with their name and then its supposed to add the name to a row in a datagridview below but I can't figure out what the code is for adding items to a datagridview in C++. If you have an example please share© 2009 Microsoft Corporation. All rights reserved.Sat, 04 Jul 2009 03:32:03 Zb5bf9ce7-7251-4a76-8a94-b48ed6f7a4edhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b5bf9ce7-7251-4a76-8a94-b48ed6f7a4ed#b5bf9ce7-7251-4a76-8a94-b48ed6f7a4edhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b5bf9ce7-7251-4a76-8a94-b48ed6f7a4ed#b5bf9ce7-7251-4a76-8a94-b48ed6f7a4edcheatcountryhttp://social.msdn.microsoft.com/Profile/en-US/?user=cheatcountrycan't figure out how to add items to a datagridviewI know how to add rows to a datagridview in VB and C# but I can't seem to figure out how to do it in C++. I have a textbox that the user fills in with their name and then its supposed to add the name to a row in a datagridview below but I can't figure out what the code is for adding items to a datagridview in C++. If you have an example please shareThu, 02 Jul 2009 06:42:07 Z2009-07-02T06:42:07Zhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b5bf9ce7-7251-4a76-8a94-b48ed6f7a4ed#410daf5d-43db-47c7-8633-a982c495690dhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b5bf9ce7-7251-4a76-8a94-b48ed6f7a4ed#410daf5d-43db-47c7-8633-a982c495690dNishant Sivakumarhttp://social.msdn.microsoft.com/Profile/en-US/?user=Nishant%20Sivakumarcan't figure out how to add items to a datagridviewIt should be pretty much the same as you'd do with C# - except for syntactic changes. Where exactly do you have a problem?<hr class="sig"><a href="http://blog.voidnish.com">http://blog.voidnish.com</a>Thu, 02 Jul 2009 15:40:42 Z2009-07-02T15:40:42Zhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b5bf9ce7-7251-4a76-8a94-b48ed6f7a4ed#b194766f-ecc1-4dff-bd37-8325df64d265http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b5bf9ce7-7251-4a76-8a94-b48ed6f7a4ed#b194766f-ecc1-4dff-bd37-8325df64d265cheatcountryhttp://social.msdn.microsoft.com/Profile/en-US/?user=cheatcountrycan't figure out how to add items to a datagridviewIn C# you do datagridview.Rows.Add(stuff here) but with C++ there is no method for Rows or a method for adding that I have been able to find.Thu, 02 Jul 2009 20:32:37 Z2009-07-02T20:32:37Zhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b5bf9ce7-7251-4a76-8a94-b48ed6f7a4ed#5432e5aa-c3f2-4334-9055-50f10dcdadfehttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b5bf9ce7-7251-4a76-8a94-b48ed6f7a4ed#5432e5aa-c3f2-4334-9055-50f10dcdadfejinzaihttp://social.msdn.microsoft.com/Profile/en-US/?user=jinzaican't figure out how to add items to a datagridviewIts the same method in C++.<br/><br/>ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.windows.forms/html/e940b01d-aea2-966f-5221-ecf4a7d7424b.htm<br/><br/>That link takes you to examples for DataGridView.Rows Here is the C++ snippet from there, which uses that same method:<br/><br/> <pre> void InitializeDataGridView() { this-&gt;Size = System::Drawing::Size( 600, 600 ); dataGridView1-&gt;Size = System::Drawing::Size( 450, 400 ); // Create an unbound DataGridView by declaring a column count. dataGridView1-&gt;ColumnCount = 4; dataGridView1-&gt;ColumnHeadersVisible = true; // Set the column header style. DataGridViewCellStyle ^ columnHeaderStyle = gcnew DataGridViewCellStyle; columnHeaderStyle-&gt;BackColor = Color::Aqua; columnHeaderStyle-&gt;Font = gcnew System::Drawing::Font( &quot;Verdana&quot;,10,FontStyle::Bold ); dataGridView1-&gt;ColumnHeadersDefaultCellStyle = columnHeaderStyle; // Set the column header names. dataGridView1-&gt;Columns[ 0 ]-&gt;Name = &quot;Recipe&quot;; dataGridView1-&gt;Columns[ 1 ]-&gt;Name = &quot;Category&quot;; dataGridView1-&gt;Columns[ 2 ]-&gt;Name = &quot;Main Ingredients&quot;; dataGridView1-&gt;Columns[ 3 ]-&gt;Name = &quot;Rating&quot;; // Populate the rows. array&lt;String^&gt;^row1 = gcnew array&lt;String^&gt;{ &quot;Meatloaf&quot;,&quot;Main Dish&quot;,&quot;ground beef&quot;,&quot;**&quot; }; array&lt;String^&gt;^row2 = gcnew array&lt;String^&gt;{ &quot;Key Lime Pie&quot;,&quot;Dessert&quot;,&quot;lime juice, evaporated milk&quot;,&quot;****&quot; }; array&lt;String^&gt;^row3 = gcnew array&lt;String^&gt;{ &quot;Orange-Salsa Pork Chops&quot;,&quot;Main Dish&quot;,&quot;pork chops, salsa, orange juice&quot;,&quot;****&quot; }; array&lt;String^&gt;^row4 = gcnew array&lt;String^&gt;{ &quot;Black Bean and Rice Salad&quot;,&quot;Salad&quot;,&quot;black beans, brown rice&quot;,&quot;****&quot; }; array&lt;String^&gt;^row5 = gcnew array&lt;String^&gt;{ &quot;Chocolate Cheesecake&quot;,&quot;Dessert&quot;,&quot;cream cheese&quot;,&quot;***&quot; }; array&lt;String^&gt;^row6 = gcnew array&lt;String^&gt;{ &quot;Black Bean Dip&quot;,&quot;Appetizer&quot;,&quot;black beans, sour cream&quot;,&quot;***&quot; }; array&lt;Object^&gt;^rows = {row1,row2,row3,row4,row5,row6}; System::Collections::IEnumerator^ myEnum = rows-&gt;GetEnumerator(); while ( myEnum-&gt;MoveNext() ) { array&lt;String^&gt;^rowArray = safe_cast&lt;array&lt;String^&gt;^&gt;(myEnum-&gt;Current); <strong>dataGridView1-&gt;Rows-&gt;Add( rowArray );</strong> } } void Button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ ) { // Resize the height of the column headers. dataGridView1-&gt;AutoResizeColumnHeadersHeight(); // Resize all the row heights to fit the contents of all non-header cells. dataGridView1-&gt;AutoResizeRows( DataGridViewAutoSizeRowsMode::AllCellsExceptHeaders); } void InitializeContextMenu() { // Create the menu item. MenuItem^ getRecipe = gcnew MenuItem( &quot;Search for recipe&quot;,gcnew System::EventHandler( this, &amp;Form1::OnMenuClick ) ); // Add the menu item to the shortcut menu. System::Windows::Forms::ContextMenuStrip^ recipeMenu = gcnew System::Windows::Forms::ContextMenuStrip(); // Set the shortcut menu for the first column. dataGridView1-&gt;Columns[ 0 ]-&gt;ContextMenuStrip = recipeMenu; } void OnMenuClick( Object^ /*sender*/, System::EventArgs^ /*e*/ ) { if ( dataGridView1-&gt;CurrentCell != nullptr ) { //Retrieve the recipe name. String^ recipeName = dynamic_cast&lt;String^&gt;(dataGridView1-&gt;CurrentCell-&gt;Value); //Search for the recipe. System::Diagnostics::Process::Start( String::Format( &quot;http://search.msn.com/results.aspx?q={0}&quot;, recipeName ), nullptr ); } } private:</pre>Thu, 02 Jul 2009 20:52:09 Z2009-07-02T20:53:33Zhttp://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b5bf9ce7-7251-4a76-8a94-b48ed6f7a4ed#5b4e9d54-d196-41e8-b950-ff8489561229http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/b5bf9ce7-7251-4a76-8a94-b48ed6f7a4ed#5b4e9d54-d196-41e8-b950-ff8489561229Nishant Sivakumarhttp://social.msdn.microsoft.com/Profile/en-US/?user=Nishant%20Sivakumarcan't figure out how to add items to a datagridviewIf you are confused about the . vs -&gt; difference, you really need to read up on C++/CLI before attempting to use it for WinForms development.<hr class="sig"><a href="http://blog.voidnish.com">http://blog.voidnish.com</a>Fri, 03 Jul 2009 03:39:37 Z2009-07-03T03:39:37Z