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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. DataGridView.remove how do i call this , help ?

DataGridView.remove how do i call this , help ?

Scheduled Pinned Locked Moved .NET (Core and Framework)
questionhelptutorial
5 Posts 3 Posters 1 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.
  • S Offline
    S Offline
    Steve Ryan
    wrote on last edited by
    #1

    New to dot Net. i have been trying to learn how to use the new datagridview in 2005. i would like to learn how to remove a row in the dataviewgrid control. could someone please help me with this. the MS documentation showed no examples. how do i get the correct row objects to do a row delete. DataGridViewRowCollection rows = this.dataGridView1.Rows; foreach (DataGridViewRowCollection Row in rows) { // // Row.remove (?) something go here or are i the wrong track } many thanks Steve steve

    M G 2 Replies Last reply
    0
    • S Steve Ryan

      New to dot Net. i have been trying to learn how to use the new datagridview in 2005. i would like to learn how to remove a row in the dataviewgrid control. could someone please help me with this. the MS documentation showed no examples. how do i get the correct row objects to do a row delete. DataGridViewRowCollection rows = this.dataGridView1.Rows; foreach (DataGridViewRowCollection Row in rows) { // // Row.remove (?) something go here or are i the wrong track } many thanks Steve steve

      M Offline
      M Offline
      Mr Brown Shoes
      wrote on last edited by
      #2

      Hi, The DataGridView is a visual representation of the data to which it's bound, so the best way to remove a row is to remove it from said bound data source. Also, be weary of code such as: foreach (DataGridViewRowCollection Row in rows) { // // Row.remove (?) } As you are removing something from a collection you're currently searching through.. that can get messy.

      1 Reply Last reply
      0
      • S Steve Ryan

        New to dot Net. i have been trying to learn how to use the new datagridview in 2005. i would like to learn how to remove a row in the dataviewgrid control. could someone please help me with this. the MS documentation showed no examples. how do i get the correct row objects to do a row delete. DataGridViewRowCollection rows = this.dataGridView1.Rows; foreach (DataGridViewRowCollection Row in rows) { // // Row.remove (?) something go here or are i the wrong track } many thanks Steve steve

        G Offline
        G Offline
        Graham Nimbley
        wrote on last edited by
        #3

        Simply...

        DataGridViewRow row=dataGridView1.Rows[23];
        dataGridView1.Rows.Remove(row)

        Or

        int index=23;
        dataGridView1.Rows.RemoveAt(index)

        This will physically remove the row, rather than marking it for deletion. Graham -- modified at 21:12 Tuesday 25th April, 2006

        S 2 Replies Last reply
        0
        • G Graham Nimbley

          Simply...

          DataGridViewRow row=dataGridView1.Rows[23];
          dataGridView1.Rows.Remove(row)

          Or

          int index=23;
          dataGridView1.Rows.RemoveAt(index)

          This will physically remove the row, rather than marking it for deletion. Graham -- modified at 21:12 Tuesday 25th April, 2006

          S Offline
          S Offline
          Steve Ryan
          wrote on last edited by
          #4

          i will reframe from messing with the collection and will just remove the row item number as an int many thanks guys steve

          1 Reply Last reply
          0
          • G Graham Nimbley

            Simply...

            DataGridViewRow row=dataGridView1.Rows[23];
            dataGridView1.Rows.Remove(row)

            Or

            int index=23;
            dataGridView1.Rows.RemoveAt(index)

            This will physically remove the row, rather than marking it for deletion. Graham -- modified at 21:12 Tuesday 25th April, 2006

            S Offline
            S Offline
            Steve Ryan
            wrote on last edited by
            #5

            I tested this on a MS example for songs in list box "data grid" well it told me that i couldnt delete the row i then tried with a for loop in csharp and was told it could remove an uncommitted row couldnt find anything on MS on line to help me any suggestions. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { private void SetUpDataGridView() { this.Controls.Add(dataGridView1); dataGridView1.ColumnCount = 5; DataGridViewCellStyle style = dataGridView1.ColumnHeadersDefaultCellStyle; style.BackColor = Color.Navy; style.ForeColor = Color.White; style.Font = new Font(dataGridView1.Font, FontStyle.Bold); dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter; dataGridView1.Name = "dataGridView1"; dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders; dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised; dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single; dataGridView1.GridColor = SystemColors.ActiveBorder; dataGridView1.RowHeadersVisible = false; dataGridView1.Columns[0].Name = "Release Date"; dataGridView1.Columns[1].Name = "Track"; dataGridView1.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridView1.Columns[2].Name = "Title"; dataGridView1.Columns[3].Name = "Artist"; dataGridView1.Columns[4].Name = "Album"; // Make the font italic for row four. dataGridView1.Columns[4].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Italic); dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.MultiSelect = false; dataGridView1.BackgroundColor = Color.Honeydew; // dataGridView1.Dock = DockStyle.Fill; // dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting); // dataGridView1.CellParsing += new DataGridViewCellParsingEventHandler(dat

            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