Prevent Unbound DataGridView From Adding New Rows -- and more  
Author Message
DroopyPawn





PostPosted: Visual Basic Express Edition, Prevent Unbound DataGridView From Adding New Rows -- and more Top

I've been in VB6 for a LONG time and can do most anything I want with it but I'm just getting started in VB 2005 Express.

I want to rewrite my gradebook program using an unbound grid control (thinking maybe DataGridView). When I edit a cell in the last row of my grid, the grid wants to add another row on the bottom. How can I stop this

=============================================

Another option I have is to use a 3rd party control like FlexCell. Adding extra components in VB6 was easy but how do I get a new control (beyond the ones included in VB2005) like FlexCell in my VB2005 project

I figured out that I have to add a reference in the Project Properties tab, but my FlexCell does not appear in the toolbox. I was able to copy a flexgrid from one of the demo files that came with the control and then paste it into my project but there must be an easier way than that. So what are ALL the steps for adding a 3rd party control

Thanks in advance,

New Guy.


Visual Studio Express Editions21  
 
 
ahmedilyas





PostPosted: Visual Basic Express Edition, Prevent Unbound DataGridView From Adding New Rows -- and more Top

If it adds another row automatically, this is fine - you dont have to insert data into to this at all, this is to make sure that the previous row is updated with values and so on (if they have been edited) like how SQL/MS Access does when you modify a row of data, in order for it to be marked as "updatable" then you need to focus on the new row to make sure that changes are made to that row of data.



 
 
NeederOfVBHelp





PostPosted: Visual Basic Express Edition, Prevent Unbound DataGridView From Adding New Rows -- and more Top

adding on to what he said, you dont have to worry about that last row, it is not saved, is is only visual until the user starts entering data into it
 
 
DroopyPawn





PostPosted: Visual Basic Express Edition, Prevent Unbound DataGridView From Adding New Rows -- and more Top

Those are interesting answers, but neither one answers the question. I want to know how to prevent the new row from showing up. Can it be done

If not, what about the FlexCell control I still need to know how to load it.

Thanks for answering.

 
 
ahmedilyas





PostPosted: Visual Basic Express Edition, Prevent Unbound DataGridView From Adding New Rows -- and more Top

try:

Me.theDataGridView.AllowUserToAddRows = false

does this help



 
 
spotty





PostPosted: Visual Basic Express Edition, Prevent Unbound DataGridView From Adding New Rows -- and more Top

Or simply select the datagridview, click on the little arrow in the top right and uncheck - enable adding.

This ultimately sets the allowuserstoaddrows property as well.


 
 
DroopyPawn





PostPosted: Visual Basic Express Edition, Prevent Unbound DataGridView From Adding New Rows -- and more Top

allowuserstoaddrows=false would prevent my from using my grid to enter data. No big deal though. I'm going to use a 3rd party grid control with more features.

 
 
GradProd





PostPosted: Visual Basic Express Edition, Prevent Unbound DataGridView From Adding New Rows -- and more Top

I am very new to VB.NET 2005 and have a small problem that looks like a big one for me. Below is what I am doing to get queried data in the dataGridView at run time:

Private Sub CompleteOperationsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CompleteOperationsToolStripMenuItem.Click

OperationsDialog.Show()

End Sub

So on clicking event of the above code the operationsdialog form opens up which has got a workcentercombobox (which is dragged from the WC010931 dataset) and ok, cancel buttons. The code in this form what I have is:

Public Class OperationsDialog

Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

Me.DialogResult = System.Windows.Forms.DialogResult.OK

Dim WCIDfind As String

Me.WC010931BindingSource.Position = _

Me.WC010931BindingSource.Find("WCDESC_I", _

WorkCentreComboBox.Text)

WCIDfind = Me.WC010931BindingSource.Current("WCID_I").ToString

Try

Dim WR130 As DataSet = New DataSet("TWODataSet")

WR130.Tables.Add("WR010130")

Dim querycon As New SqlConnection(My.Settings.TWOConnectionString)

Dim cmdquery As SqlCommandBuilder

Dim WR130TableAdapter = New SqlDataAdapter( _

"SELECT dbo.WR010130.MANUFACTUREORDER_I, dbo.WR010130.RTSEQNUM_I, dbo.WR010130.RTSEQDES_I, dbo.WR010130.SCHEDULESTARTDATE_I, dbo.WR010130.DONECB_I " _

& "FROM dbo.WR010130 JOIN WO010032 ON dbo.WR010130.MANUFACTUREORDER_I = dbo.WO010032.MANUFACTUREORDER_I " _

& "JOIN dbo.WC010931 ON dbo.WR010130.WCID_I = dbo.WC010931.WCID_I " _

& "WHERE dbo.WR010130.DONECB_I <> 1 AND dbo.WC010931.WCDESC_I = '" & WorkCentreComboBox.Text & "' AND (dbo.WO010032.MANUFACTUREORDERST_I = 3 OR dbo.WO010032.MANUFACTUREORDERST_I = 7)" _

& "ORDER BY dbo.WR010130.SCHEDULESTARTDATE_I", querycon)

cmdquery = New SqlCommandBuilder(WR130TableAdapter)

WR130TableAdapter.Fill(WR130, "WR010130")

MainForm.WR010130DataGridView.DataSource = WR130.Tables("WR010130")

Catch ex As Exception

MsgBox(ex.Message)

End Try

MainForm.WorkCentreLabel.Show()

MainForm.WorkCentreTextLabel.Show()

MainForm.WorkCentreTextLabel.Text = WorkCentreComboBox.Text

MainForm.WR010130DataGridView.Show()

MainForm.SaveButton.Show()

Me.Close()

End Sub

Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click

Me.DialogResult = System.Windows.Forms.DialogResult.Cancel

Me.Close()

End Sub

Private Sub OperationsDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.WC010931TableAdapter.Fill(Me.TWODataSet.WC010931)

End Sub

Private Sub WC010931BindingNavigatorSaveItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)

Me.Validate()

Me.WC010931BindingSource.EndEdit()

Me.WC010931TableAdapter.Update(Me.TWODataSet.WC010931)

End Sub

Private Sub WCDESC_IComboBox_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles WorkCentreComboBox.SelectionChangeCommitted

OK_Button.Focus()

End Sub

End Class

With the help of the above code, i get the required data in my dataGridView.

The problem starts now : Of the 5 columns in the dataGridView the first 4 are read only and only the 5th column is edit column whcih is a check box. When the user checks any of the checkboxes on any row, and clicks on save the done_cb column should be updated. This means all the ticked boxes should store the value 1 in the database keeping everything else the same.

please can anyone show me how this can be done or pass on any ideas where I can look for

Thanks.