Jump to content
Xtreme .Net Talk

How to map a datagridview column to a column of the datasource datatable? [CS/C# 2005


Recommended Posts

Posted

Given a DataGridView (dgvPlayerList) used to display all the players and their current information to the user.

Given a DataSet (dsPlayerList.Tables["PlayerList"]) that house the list of players and their information to be displayed as the datasource of the datagridview (dgvPlayerList)...

 

The DataTable (PlayerList) is composed of 4 columns: [iD], [Name], [Type], [iP].

Currently I am using the following code to display the information:

 

dgvPlayerList.DataSource = dsPlayerList.Tables["PlayerList"];

 

Problem is this displays all 4 columns and I do not want to shown the [iD] or [iP] columns in the datagridview - so I tried to customize the coloumns collection by creating the [Name] and [Type] columns and setting "dgvPlayerList.AutoGenerateColumns = false;" but when I try the columns are never filled with data ...

It seems I need a way to map the datagridview column with its corresponding column in the DataSet.Tables["PlayerList"], I did some reading and people mentioned the DataMember & ValueMember field but little to no examples where provided and I couldn't get it to work. Others spoke of the DataPropertyName but again little to no examples or samples...

 

So I was hopeing someone could help shed some light on my little problem - I just want to MAP (somehow) my columns in the datagridview column collection with a specific column in the datasource datatable column...

 

Any ideas, hints, and help would be greatly appreciated, thanks

  • 6 months later...
Posted
the date says this was posted four years ago - let me know if you still need help with this.

 

I hope you can share your solution to this. I also need this.

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...