Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi All,

 

I am currently having a problem identifying the number of columns and rows in a datagrid.

 

He is my code:

       Dim rowCount As Integer
       Dim colCount As Integer
       Try
           rowCount = CType(Me.DataGrid1.DataSource, DataView).Table.Rows.Count
           colCount = CType(Me.DataGrid1.DataSource, DataView).Table.Columns.Count
       Catch ex As Exception
           MessageBox.Show(ex.Message)
       End Try

The error I am receiving is:

"Specified cast is not set"

on "rowCount = CType(Me.DataGrid1.DataSource, DataView).Table.Rows.Count" line of code.

 

Is this the correct way to be doing this?

 

Any help will be greatly appreciated.

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted

Have found answer.

 

'Need to find out the number of Rows & Columns in Datagrid
       Dim row As Integer 
       Dim col As Integer
       Dim rowCount As Integer
       Dim colCount As Integer
       Try
           rowCount = CType(Me.DataGrid1.DataSource, DataViewManager).DataSet. _
               Tables("StaticAssets").DefaultView.Table.Rows.Count
           colCount = CType(Me.DataGrid1.DataSource, DataViewManager).DataSet. _
               Tables("StaticAssets").DefaultView.Table.Columns.Count
       Catch ex As Exception
           MessageBox.Show(ex.Message)
       End Try

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...