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. few questions about database /datagrid

few questions about database /datagrid

Scheduled Pinned Locked Moved C#
databasequestioncssannouncement
4 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.
  • F Offline
    F Offline
    faladrim
    wrote on last edited by
    #1

    hi, i have a few quesions : 1. How do i highlight a entire row? this is what i have now: dataGridView1.Rows[index].Cells[0].Style.BackColor = Color.Red ; dataGridView1.Rows[index].Cells[1].Style.BackColor = Color.Red; index is the last row, but i still have to tell what column, is there way to select all culmns? 2. how do i sort on a letter in an entire table (like a search button) this is what i have now: private void btn_sort_Click(object sender, EventArgs e) { db1DataSet.tabel1.DefaultView.RowFilter = " name LIKE '%" + txt_sort.Text + "%' "; dataGridView2.DataSource=db1DataSet.tabel1.DefaultView; } name is a column, again is there a way to select all the columns? 3. How do i delete more then one row at the time. (select in a datagrid) this is what i have now: try { db1DataSet.tabel1.Rows[dataGridView1.CurrentRow.Index].Delete(); tabel1TableAdapter.Update(db1DataSet.tabel1); db1DataSet.AcceptChanges(); this.tabel1TableAdapter.Fill(this.db1DataSet.tabel1); Application.DoEvents(); } catch (System.Exception ex) { db1DataSet.RejectChanges(); lbl_error.Text= ex.Message; } here i just delete the selected item, the one with the arrow nextto in the grid if there is anyone with some idea's let me know :p thxx

    C F 2 Replies Last reply
    0
    • F faladrim

      hi, i have a few quesions : 1. How do i highlight a entire row? this is what i have now: dataGridView1.Rows[index].Cells[0].Style.BackColor = Color.Red ; dataGridView1.Rows[index].Cells[1].Style.BackColor = Color.Red; index is the last row, but i still have to tell what column, is there way to select all culmns? 2. how do i sort on a letter in an entire table (like a search button) this is what i have now: private void btn_sort_Click(object sender, EventArgs e) { db1DataSet.tabel1.DefaultView.RowFilter = " name LIKE '%" + txt_sort.Text + "%' "; dataGridView2.DataSource=db1DataSet.tabel1.DefaultView; } name is a column, again is there a way to select all the columns? 3. How do i delete more then one row at the time. (select in a datagrid) this is what i have now: try { db1DataSet.tabel1.Rows[dataGridView1.CurrentRow.Index].Delete(); tabel1TableAdapter.Update(db1DataSet.tabel1); db1DataSet.AcceptChanges(); this.tabel1TableAdapter.Fill(this.db1DataSet.tabel1); Application.DoEvents(); } catch (System.Exception ex) { db1DataSet.RejectChanges(); lbl_error.Text= ex.Message; } here i just delete the selected item, the one with the arrow nextto in the grid if there is anyone with some idea's let me know :p thxx

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      faladrim wrote:

      db1DataSet.tabel1.DefaultView.RowFilter = " name LIKE '%" + txt_sort.Text + "%' ";

      Get rid of the % before txt_sort and it will sort alphabetically for you.

      faladrim wrote:

      How do i delete more then one row at the time. (select in a datagrid)

      Probably by writing the SQL to delete the right items.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      1 Reply Last reply
      0
      • F faladrim

        hi, i have a few quesions : 1. How do i highlight a entire row? this is what i have now: dataGridView1.Rows[index].Cells[0].Style.BackColor = Color.Red ; dataGridView1.Rows[index].Cells[1].Style.BackColor = Color.Red; index is the last row, but i still have to tell what column, is there way to select all culmns? 2. how do i sort on a letter in an entire table (like a search button) this is what i have now: private void btn_sort_Click(object sender, EventArgs e) { db1DataSet.tabel1.DefaultView.RowFilter = " name LIKE '%" + txt_sort.Text + "%' "; dataGridView2.DataSource=db1DataSet.tabel1.DefaultView; } name is a column, again is there a way to select all the columns? 3. How do i delete more then one row at the time. (select in a datagrid) this is what i have now: try { db1DataSet.tabel1.Rows[dataGridView1.CurrentRow.Index].Delete(); tabel1TableAdapter.Update(db1DataSet.tabel1); db1DataSet.AcceptChanges(); this.tabel1TableAdapter.Fill(this.db1DataSet.tabel1); Application.DoEvents(); } catch (System.Exception ex) { db1DataSet.RejectChanges(); lbl_error.Text= ex.Message; } here i just delete the selected item, the one with the arrow nextto in the grid if there is anyone with some idea's let me know :p thxx

        F Offline
        F Offline
        freshonlineMax
        wrote on last edited by
        #3

        Hi 1.Select entire row in datagrid : private void dataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { System.Drawing.Point pt = new Point(e.X, e.Y); DataGrid.HitTestInfo hti = dataGridSearch.HitTest(pt); if (hti.Row == dataGridSearch.VisibleRowCount-1) // "The Last Null Row" return ; dataGrid.Select(hti.Row); } 2. I didn't understand clicking on datagrid's column headers can sort columns. 3.Delete multi rows : You should add one checked (boolean) column to your dataset's table. then datagrid show it, after user checks this columns, you can find checked chekboxes and delete them all.

        F 1 Reply Last reply
        0
        • F freshonlineMax

          Hi 1.Select entire row in datagrid : private void dataGrid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { System.Drawing.Point pt = new Point(e.X, e.Y); DataGrid.HitTestInfo hti = dataGridSearch.HitTest(pt); if (hti.Row == dataGridSearch.VisibleRowCount-1) // "The Last Null Row" return ; dataGrid.Select(hti.Row); } 2. I didn't understand clicking on datagrid's column headers can sort columns. 3.Delete multi rows : You should add one checked (boolean) column to your dataset's table. then datagrid show it, after user checks this columns, you can find checked chekboxes and delete them all.

          F Offline
          F Offline
          faladrim
          wrote on last edited by
          #4

          a little more about the sorting, i only show the items that contain the text form the textbox, maybe sorting istn the right word :p more like a search and thx

          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