Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'll try to keep this simple.

  • Small C# app, dialog based, one has a DataGridView.

  • I've got an UpdateTable function in the form that accepts a DataSet and passes it to the DataGridView.DataSource.  The DataGridView has columns defined already.

  • I've never used DataGridView and whatnot, so I was doing a bit of testing with it by passing it a DataSet I'd constructed myself.  Using this method gives me the correct number of rows, however the entries were all blank.

  • When I set the DataGridViewTextBoxColumn.DataPropertyName to the same as the column names in the DataSet, the entries show up.

  • If I remove the premade columns from the DataGridView, I get everything in the DataSet, but the columns are (obviously) unformatted in terms of size, and the column names are the names of the columns in the DataSet rather than easier to read / formatted names.

What's a good way to handle this in an MVP implementation, where the View doesn't have to know or worry about what columns will be in the DataSet it's being handed, but the column names can still be formatted properly in terms of size and name?  Should perhaps the Presenter pass in a vector of strings of DataPropertyNames, Column Names, and column sizes, so the View isn't cognizant of it?  

share|improve this question
3  
I think this belongs on Stackoverflow...programming how to question. –  Mike Brown Mar 28 '11 at 23:51
    
I also think this belongs in SO. FWIW, you might want to forget for a while about DataGridView and think about how you would solve the problem if the UI was a rich WUI. –  Apalala Mar 29 '11 at 2:11
    
Well, the thing is I've figured out how-to, what I'm trying to figure out is how-should-in-MVP. –  trycatch Mar 29 '11 at 13:36
add comment

1 Answer

up vote 1 down vote accepted

There are attributes in System.ComponentModel that you can set on your DataSet Columns which a DataGrid will honor. DisplayName for example will tell the grid what to display on the column header. Is this Windows Forms?

share|improve this answer
    
It is, all the dialogs are derivatives of System.Windows.Forms. I'll certainly give what you said a try. Sorry for the delay in response, I essentially only had time to post and run for the day and hope for something to go on when I returned.. This sounds very good though, what I was looking for, keeps the View blind to the Model. –  trycatch Mar 29 '11 at 13:48
    
Actually.. I'm having finding any good examples of using System.ComponentModel or finding anything that looks promising in the MSDN.. I've found "Caption" in DataColumn but that doesn't seem to work, I've set that and passed it to a Table and to a DataGrid but no bite. (And still can't find anything about column widths or anything..) –  trycatch Mar 29 '11 at 14:21
    
I'll be able to give some more info later. I don't think there's a way to set width using metadata without extending DataColumn. –  Mike Brown Mar 29 '11 at 14:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.