Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VS2005 VS2008 C# Visual-Studio , +
I am trying to make a database program in visual studio 2008....i need to show some blank or empty rows in a datagrid to make my program look nice for this i used
 
public frmMainWindow()
        {
            InitializeComponent();
             dataGridView1.Rows.Add(7);
             dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        } 

 

 

 
i needed to select whole rows when a user select a cell in a data grid so i used the second line code for it...
but i don't wish user to be able to select the empty cell or rows....
 
i tried this code
 
 
<pre lang="cs">private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    if (dataGridView1.CurrentCell.Value == null)
    {
 
        dataGridView1.ClearSelection();
    }
 
 

but a flash of section occurs before the selection is removed using that code...
i want it not to be selected at all even for a second...
thank you for your help
Posted 19-Jul-11 1:02am
amsainju1.3K
Edited 19-Jul-11 2:18am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I got the solution myself:
 

private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
          if (dataGridView1.CurrentCell.Value == null)
           {
 
           dataGridView1.ClearSelection();
            }
        }
 

 
using this the flash of selection did not appeared....
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
Try this
 
For(int i =0;i< this.dataGridView1.CurrentRow.Cells.Count;i++)//Some thing like this .Count or .Length
{
if(this.dataGridView1.CurrentRow.Cells[i].Value == null)
}
 
Rate the solution if u like
  Permalink  
v3
Comments
amsainju at 19-Jul-11 6:14am
   
hi,
i didn't get it...
how this could disable the selection of the cell if the cell is null
Syed Salman Raza Zaidi at 19-Jul-11 6:52am
   
First i executed a loop to ge total no of columns of the grid,then i am checking whether at the selected row's cell value is null or not :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 19 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100