|
-
Apr 17th, 2007, 11:46 PM
#1
Thread Starter
Just Married
[RESOLVED] [2.0] DataGridView
Hi all
I want to fill the DataGridView Manully and set the column value.
This I does in VB.NET
vb Code:
For I As Integer = 0 To DataTable.Rows.Count - 1 Step I + 1
gridTable.Rows.Add(1)
gridTable.Item(0, I).Value = DataTable.Rows(I)(2).ToString
Next
This is in C#
but
C# Code:
int i = 0;
for (i = 0 ; i< dataTable.Rows.Count;i++)
{
this.gridTable.Rows.Add(1);
//I am Confused Here
}
Thanks
-
Apr 18th, 2007, 12:04 AM
#2
Re: [2.0] DataGridView
The code is exactly the same in C#. The only difference is the colon on the end and the fact that when you index something in C# you use square brackets instead of parentheses like in VB. This:
vb Code:
gridTable.Item(0, I).Value = DataTable.Rows(I)(2).ToString
becomes this:
Code:
gridTable.Item[0, I].Value = DataTable.Rows[I][2].ToString();
Note also that you must ALWAYS include the parentheses when calling a method in C#, as I have done with ToString. I think that you should always do so in VB too to differentiate methods from properties. This is enforced in C# but not in VB.
-
Apr 18th, 2007, 12:59 AM
#3
Thread Starter
Just Married
Re: [2.0] DataGridView
Thanks sir
C# Code:
this.gridTable.Item[0, i].Value = dataTable.Rows[i][2].ToString();
But the error saying that System.Windows.Forms.DataGridView' does not contain a definition for 'Item'
and what that mean
you must ALWAYS include the parentheses when calling a method in C#, as I have done with ToString. I think that you should always do so in VB too to differentiate methods from properties. This is enforced in C# but not in VB.
-
Apr 18th, 2007, 01:25 AM
#4
Re: [2.0] DataGridView
Ah, sorry. Missed that. In VB.NET you have default properties. In C# the equivalent are indexers. With a default property in VB you have the choice of specifying the property:or omitting the property name and indexing the object directly:In C# you don't have the choice. Only the second option is available:
-
Apr 18th, 2007, 05:25 AM
#5
Thread Starter
Just Married
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|