Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. About DataGrid

About DataGrid

Scheduled Pinned Locked Moved C#
databasehelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amir Jalaly
    wrote on last edited by
    #1

    Hi i work in a project about database and use datagrid . i want to prevent user from adding new record ( by clicking the * sign in datagrid ) but i can not find anything like allowAdd or CanAdd for disabling the add ability . can someone help me ? Regards Amir Jalaly

    A 1 Reply Last reply
    0
    • A Amir Jalaly

      Hi i work in a project about database and use datagrid . i want to prevent user from adding new record ( by clicking the * sign in datagrid ) but i can not find anything like allowAdd or CanAdd for disabling the add ability . can someone help me ? Regards Amir Jalaly

      A Offline
      A Offline
      Alomgir Miah
      wrote on last edited by
      #2

      The DataGrid class does not have a property that controls whether a new row can be added. But the DataView class does have such a property (along with some others such as AllowEdit and AllowDelete). Here is code that will turn off the append row by getting at the dataview associated with the datagrid. string connString = @"Provider=Microsoft.JET.OLEDB.4.0;data source=C:\northwind.mdb"; string sqlString = "SELECT * FROM customers"; // Connection object OleDbConnection connection = new OleDbConnection(connString); // Create data adapter object OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sqlString, connection); // Create a dataset object and fill with data using data adapter's Fill method DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet, "customers"); // Attach dataset's DefaultView to the datagrid control dataGrid1.DataSource = dataSet.Tables["customers"]; //no adding of new rows thru dataview... CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember]; ((DataView)cm.List).AllowNew = false; If your datagrid contains links, then adding Navigate handler such as the one below to disallow the AddNew. private void DataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne) { if(ne.Forward) { CurrencyManager cm = (CurrencyManager)BindingContext[DataGrid1.DataSource,DataGrid1.DataMember]; DataView dv = (DataView) cm.List; dv.AllowNew = false; } } Live Life King Size Alomgir Miah

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups