Click here to Skip to main content
15,884,692 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 19-Jul-11 1:18am
v3

I got the solution myself:


C#
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
          if (dataGridView1.CurrentCell.Value == null)
           {

           dataGridView1.ClearSelection();
            }
        }




using this the flash of selection did not appeared....
 
Share this answer
 
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
 
Share this answer
 
v3
Comments
amsainju 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900