Windows Develop Bookmark and Share   
 index > Windows Forms General > Regex and datagrids..
 

Regex and datagrids..

I am trying to get a count of all instances of "IN" from a populated datagrid using:

Private Sub Counts()

Dim INCount As Integer = 0
Dim INFinder As Regex = New Regex("IN")

For Each row As DataGridViewRow In Me.dgResults.Rows
For Each cell As DataGridViewCell In row.Cells
INCount += INFinder.Matches(cell.ToString).Count
Next
Next

tslIN.Text = INCount
tslOUT.Text = Math.Abs(INCount - dgResults.RowCount)

End Sub

But instead "cell.ToString" is yielding "DataGridViewTextBoxCell { ColumnIndex=0, RowIndex=0 }" ????

Any ideas?
Also what would be the best way to search on a specific column?

TIA,
Stue

Stankerific  Tuesday, January 09, 2007 7:42 PM

use

cell.Value instead of cell.ToString

Naga Satish Rupenaguntla  Tuesday, January 09, 2007 11:01 PM

use

cell.Value instead of cell.ToString

Naga Satish Rupenaguntla  Tuesday, January 09, 2007 11:01 PM

I did that before but being new and all didnt fully understand the error about the invallid casting of dbnull.. but now I understand why and am trying to figure out a way to skip if null.

Thanks for your help!

Stue

Stankerific  Wednesday, January 10, 2007 3:59 PM

You can use google to search for other answers

Custom Search

More Threads

• 'child' is not a child control of this parent
• Stupid problem with a Label in a statusStrip
• C# 2003 - Windows Forms Events
• pixel relative to milimiter
• VS 2008 and strange things
• How to use an event an another class to report progress in Main thread using BackgroundWorker.
• Creating an updatable windows application (PATCH)
• listview problem
• Design view cue for UserControls
• ToolStrip layout when moving it to different parts of a ToolStripContainer