Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Trust the Universe
Posted

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

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

Posted

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:

Trust the Universe
Posted (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 by feurich
Trust the Universe

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...