Windows.Forms.Datagrid Want Delete, don't want New Row.

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Hi,
Is there anyway to stop the datagrid from displaying the 'new record'
position at the bottom but still retain the ability to delete records?
Thanks
Bob
 
Bob said:
Hi,
Is there anyway to stop the datagrid from displaying the 'new record'
position at the bottom but still retain the ability to delete
records?

If your DataGrid is bound to a DataView, you can set the DataView's
AllowNew to False.

Otherwise, I dunno... try setting ReadOnly to True and capturing Delete
keypresses?
 
Bob,

Yes very simple because they are seperated.
in the datasource
when it is a datatable
dt.datasource.allownew = false
when it is a dataview
dv.allownew = false

When you than want to add new with a button you can set it to allownew =
true and back to false, because there is no paining in a method when you
don't force that the user will not see that.

I hope this helps?

Cor
 
Hi Larry & Cor,
Thanks for the advice.
Cor thought that the Datatable.Datasource exposed the allownew, but I can't
find it.
It seems that I will have to bind the Datagrid to a dataview to get this
functionality.
regards
Bob
 
Hi Cor,
Tried it,
Code executes OK but new row still appears.
Final Solution below.
There is a gotcha. The SetDataBinding doesn't work with the dataview
parameters which sent me off into the weeds for a while.
regards
bob
'mdsUnits.Tables(0).DefaultView.AllowNew = False 'Executes OK but still
shows new row

mdvUnits = New DataView(mdsUnits.Tables(0), "", "unit",
DataViewRowState.CurrentRows)

mdvUnits.AllowNew = False

Me.dgUnitList.DataSource = mdvUnits

Me.dgUnitList.DataMember = mdvUnits.Table.ToString ' not really necessary.
(Single Table datasource)

'Me.dgUnitList.SetDataBinding(mdsUnits, mdsUnits.Tables(0).ToString)
'Original, has 'new' row

'Me.dgUnitList.SetDataBinding(mdvUnits, mdvUnits.Table.ToString)NO! Don't
work gives blank datagrid
 
Bob,

Are you using relations,

Otherwise is this probably more than enough
dgUnitlist.Datasource = mdsUnits.Tables(0).Defaultview

That defaultview is the in build dataview in the datatable.

I mostly use as well mostly without thinking
dim dv as new dataview(mdsUnits.Tables(0))
dgUnitlist.Datasource = dv

(Probably only because dv is than easier typing it goes automaticly)

However I showed you the first to let you know the possibility

I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top