DataGridView Knowledge
1. this.dataGridView1.RowHeadersWidth = 25;//gets and sets the width of the column for the row header (first column)
2. This.dataGridView1.AutoResizeColumns ()//Adjusts the width of all columns to fit the contents of all its cells, including the header cell
3. BindingManagerBase: Data Binding
in Visual C # data binding, you've learned how to bind certain fields in a dataset to a property of the WinForm component, so that programmers can customize the form of data display based on the WinForm component. And the WinForm component display at this point can change as the record pointer changes. Thus, the key to browsing data logging is how to change the record pointer. To do this, you use the BindingManagerBase class, whose primary role is to manage objects that are implemented to bind to the same data source. Specifically, you can synchronize components on a Windows Form that have data binding to the same data source. A property "Position" is defined in the BindingManagerBase class to change the data pointer in the BindingManagerBase object. Creating a BindingManagerBase object must use the BindingContext class, in fact, each object that is inherited from the control class has a single BindingContext object. The BindingManagerBase object that implements the data-binding component in most creation forms is obtained using the BindingContext of the form class. To delete a row: Multiple TextBox controls on a WinForm display a record in a table in a database whose data source is bound to a dataset and when the Delete button is pressed, the record in the database table is deleted, but the control is also displayed (because the dataset is not updated). I would like to see the effect of the deletion from the WinForm, that is: The DataSet will also update
private void Button2_Click (object sender, EventArgs e)
{
if (Datagridview1.currentcell = = null)
{
MessageBox.Show ("No elements in the table can be deleted");
}
else
{
BindingManagerBase BMB = (bindingmanagerbase) this.datagridview1.bindingcontext[ This.dataGridView1.DataSource];
DataRowView DRV = (DataRowView) bmb. Current;
int position = BMB. Position;
DataRow dr = DRV. Row;
Dr. Delete ();
}
}