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