feurich Posted February 12, 2009 Posted February 12, 2009 Hi There, I am making a database dialog control that is an add-in to another program. It should give the user the abillity to search from that Database Dialog in to a database. De datagridview is databound to a table via a sql dataset. So the header information is there Now I would like to keep the first row of the datagridview empty to give the user the possibility to enter in the colomns they want search information and then klik on a button search and the dialog will perform the SQL query with the entered values for the columns. How can I leave the first row of the datagridview empty? I have tried almost everything except customizing the datagridview. If here is a other option please let me know. All the best. Quote Trust the Universe
DPrometheus Posted February 12, 2009 Posted February 12, 2009 You can insert rows even after binding with [grid].rows.Insert To bind to a xml file and add an empty row above you can do just this: Try Dim dset As DataSet = New DataSet() dset.ReadXml("sales_by_category.xml") DataGridView1.BindData(dset, "category") DataGridView1.Rows.Insert(0, 1) Catch ex As Exception MsgBox(ex.Message) End Try this snippet inserts a blank row at index 0, the 1 stands for count. Since we want just 1 row, count equals 1. ~DP Quote My Development System Intel Core i7 920 @2.66Ghz 6 GB DDR3 SDRAM Windows 7 Ultimate x64 & Windows Vista Home Premium x64 dual boot GeForce GTX295 1.8 GB 3.5 TB HD
feurich Posted February 12, 2009 Author Posted February 12, 2009 I tried to do so but I get the message "Rows cannot programmatically be added to the Datagridview's rows collection when the control is data-bound". The DataGridView control is bound to a DataTable and after that I am trying to add the row. Is this possible I ask myself and DPrometheus ? :confused: Quote Trust the Universe
feurich Posted February 12, 2009 Author Posted February 12, 2009 (edited) It was not as direct as I thought. The following is the solution for this question: DataTable dbTable = new DataTable(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmdString,connString); // Add empty Row to dataTable DataRow dataRow; dataRow = dbTable.NewRow(); dbTable.Rows.InsertAt(dataRow, 0); sqlDataAdapter.Fill(dbTable); dataGridView1.DataSource = dbTable; Edited February 12, 2009 by feurich Quote Trust the Universe
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.