bind datasource to Datagridview - possible to do like VB.net?

R

Rich

I am migrating from VB.net to C# (after about 8 years with VB.Net)

Here is how I managed to bind a datasource to my datagridview in C#, and
below that is how I do it in VB.Net. Question is if I can change the C# code
here to be a little less verbose like the VB.net sample?

//C#
BindingSource bs = new BindingSource();
bs.DataSource = ds; //ds is a dataset
bs.DataMember = ds.Tables[0].TableName;
//bs.DataMember = ds.Tables("tbl1"); <--vb.net style - is there a way to use
//tablename directly instead of ds.Tables.Tablename ?
dgrv1.DataSource = bs;
dgrv1.Refresh();

'--VB.net
dgrv1.DataSource = ds.Tables("tbl1")
 
R

Rich

Thanks. I did some C# coding in VS2003 but not extensive like VB.net. I
guess I will have a bit of a learning curve during the migration process.

Martin Honnen said:
Rich said:
'--VB.net
dgrv1.DataSource = ds.Tables("tbl1")

C#
dgrv1.DataSource = ds.Tables["tbl1"];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top