How to make a datagrid view cell not selected at form load for this
I have tried too much
my dgvproducts properties are (readonly = false,selection mode = CellSelect)
1) i have place this code in form shown
event but that does not work for me ..
dgvProducts.Clearselection();
2) I have place the above code in databinding event
like the below..
private void dgvProducts_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
//dgvProducts.ClearSelection();
((DataGridView)sender).ClearSelection();
}
it does not work for me ...
3) i have placed similar code and i have added extra line to that in form load event
but does not work for me ..
dgvProducts.ClearSelection();
dgvProducts.currentcell = null;
but this is not work for me ....
this is my form load code
private void SellEquipment_Load(object sender, EventArgs e)
{
getProductDetails();
dgvProducts.Columns[0].Visible = false;
for (int i = 0; i < dgvProducts.Columns.Count; i++)
if (dgvProducts.Columns[i] is DataGridViewImageColumn)
{
((DataGridViewImageColumn)dgvProducts.Columns[i]).ImageLayout = DataGridViewImageCellLayout.Stretch;
break;
}
}
and this is my getproductdetails code
private void getProductDetails()
{
var products = from productlist in dbcontext.products
select new
{
productid = productlist.productId,
Name = productlist.Name,
Image = productlist.Image,
Description = productlist.Description,
Price = productlist.Price
};
BindingProductsource.DataSource = products;
dgvProducts.DataSource = BindingProductsource;
dgvProducts.ClearSelection();
}
would any one pls help on this..
Many thanks...
Try creating a new event OnShow and do this code:
protected override void OnShown(EventArgs e)
{
if (this.dataGridView1.SelectedCells.Count > 0)
{
for (int i = 0; i < this.dataGridView1.SelectedCells.Count; i++)
this.dataGridView1.SelectedCells[i].Selected = false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With