How do I select rows in DataGrid with values  
Author Message
Alessandro Camargo





PostPosted: Visual C# Express Edition, How do I select rows in DataGrid with values Top

Hi,

How can I select all rows on tableviewgrid However, I don't want to select a new row i.e:

colunm1 | column2

------------------------------

1 | 'xxx'

2 | 'ddd'

* null | null -> new row

When I use selectall(), new row is always selected, but I don't want. How do I select rows with values

cheers,




Visual Studio Express Editions27  
 
 
ahmedilyas





PostPosted: Visual C# Express Edition, How do I select rows in DataGrid with values Top

SelectAll will of course select all the rows, even if no data is there/new row.

why dont you, when processing the selected cells, check to see if the last row contains data and if not then skip it and do the rest of your process request

i will see what I can come up with - not thinking the usual self at the moment!

 



 
 
ahmedilyas





PostPosted: Visual C# Express Edition, How do I select rows in DataGrid with values Top

try this:

DataGridViewRowCollection theCollection = this.theDataGridView1.Rows; //since you are selecting all the rows anyway

theCollection.RemoveAt(this.theDataGridView1.Count);

you will now have all the rows copied, except the last row, into the DataGridViewRowCollection

does this help



 
 
Alessandro Camargo





PostPosted: Visual C# Express Edition, How do I select rows in DataGrid with values Top

Ok, I got it

I think my questions was wrong.......I want select all row on datagridview, except the new row

of couse if choose selectall() all of them will selected, therefore, How can I select all rows



 
 
ahmedilyas





PostPosted: Visual C# Express Edition, How do I select rows in DataGrid with values Top

try the code I suggested in the previous post - it will select all rows not including the last row, which would be the blank "new row", stored in the DataGridViewRowCollection variable - containing all the rows NOT including the last row as the blank "new row" - sorry, re-iterating myself!

 
 
Alessandro Camargo





PostPosted: Visual C# Express Edition, How do I select rows in DataGrid with values Top

Ok,

the collection ok, but how after this selecting all row in visual mode, I meam like selectall()

cheers,



 
 
ahmedilyas





PostPosted: Visual C# Express Edition, How do I select rows in DataGrid with values Top

in visual mode, I guess is a bit more trickier. Do you have to unselect the last row I am still seeing what I can come up with

 
 
Alessandro Camargo





PostPosted: Visual C# Express Edition, How do I select rows in DataGrid with values Top

Yes, I do. this is the problem. I guess there is some thing like this

while( DataGridView.row != maxrow)

{

DataGridView.row.selected = true

}

But I couldn't find it

cheers,



 
 
ahmedilyas





PostPosted: Visual C# Express Edition, How do I select rows in DataGrid with values Top

yes, well, I found a way but this will be ineffecient:

 

foreach (DataGridViewRow curRow in this.theDataGridView.Rows)

{

   if (curRow.Index == this.theDataGridView.Rows.Count - 1)

   {

      curRow.Selected = false;

   }

}

 

I will post a more effecient way once I get there



 
 
ahmedilyas





PostPosted: Visual C# Express Edition, How do I select rows in DataGrid with values Top

effecient way,

this.theDataGridView.Rows[this.theDataGridView.Rows.Count - 1].Selected = false;

hope this helps

lacking sleep over here, performance is poor :-(



 
 
Alessandro Camargo





PostPosted: Visual C# Express Edition, How do I select rows in DataGrid with values Top

Yes, it works. I think you can go to sleep now

cheers