Click here to Skip to main content
15,891,372 members
Home / Discussions / C#
   

C#

 
GeneralRe: Path stroke with multiple colors? Pin
SledgeHammer012-Dec-14 18:28
SledgeHammer012-Dec-14 18:28 
QuestionEmail Delivery Receipt Pin
Jassim Rahma1-Dec-14 21:12
Jassim Rahma1-Dec-14 21:12 
AnswerRe: Email Delivery Receipt Pin
BillWoodruff1-Dec-14 21:16
professionalBillWoodruff1-Dec-14 21:16 
GeneralRe: Email Delivery Receipt Pin
Jassim Rahma1-Dec-14 21:18
Jassim Rahma1-Dec-14 21:18 
GeneralRe: Email Delivery Receipt Pin
OriginalGriff1-Dec-14 21:34
mveOriginalGriff1-Dec-14 21:34 
Questionstrong encryption Pin
Jassim Rahma1-Dec-14 0:44
Jassim Rahma1-Dec-14 0:44 
SuggestionRe: strong encryption Pin
Richard MacCutchan1-Dec-14 1:19
mveRichard MacCutchan1-Dec-14 1:19 
Question[Solved] DataGridView, BindingList and combining object properties? Pin
ixilom30-Nov-14 5:54
ixilom30-Nov-14 5:54 
Hi,

I'm having a problem with using a BindingList as DataSource for a DataGridView.
The BindingList and the objects in it come from another assembly, thus I cannot modify the object itself to conform to what I want to display in a DataGridView column.
Basically, the object looks something like this:
C#
public class DownloadItem : INotifyPropertyChanged
{
	public int Progress { get; private set;}
	public string State { get; private set;}
	/*
	... more properties
	*/
}

In my own program (my assembly) I would bind the items like this:
C#
/*
GetDownloads() returns BindingList<DownloadItem>
*/
dataGridViewDownloads.DataSource = _manager.GetDownloads();

Instead of having two columns (Progress and State) I would like to combine them to one (Status) which would display something like "23% Downloading".

I've made my own classes for custom column/cell (DataGridViewTextBoxCell and DataGridViewColumn) but from what I can tell, you can only have one PropertyName assigned to the column.

My initial thought was to create some sort of adapter for the DownloadItem class, but I'm not sure how I would create such adapter without creating another BindingList holding the adapter versions of DownloadItem, which in turn would then break the INotifyPropertyChange interface.

Searching for DataGridView and Adapter gives me results about SqlDataAdapter or DataTable. And I know the SQL adapter is not what I need. Not Sure about the DataTable though?

I would appreciate any hints and thoughts on this, or even hints on what I should search for.


[Solved, sort of]
I found a hackish way to do this without any kind of adapters:
C#
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
            DataGridViewElementStates cellState, object value, object formattedValue, string errorText,
            DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
{
	StringFormat stringFormat = new StringFormat { 
		Alignment = StringAlignment.Center, 
		LineAlignment = StringAlignment.Center, 
		Trimming = StringTrimming.None, 
		FormatFlags = StringFormatFlags.NoClip | StringFormatFlags.NoWrap 
	};
	base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, 
		formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
	/*
	Here I access the underlying object for this row
	*/
	var item = (DownloadItem)DataGridView.Rows[rowIndex].DataBoundItem;
	/*
	Now I can display whatever properties I can get from the DownloadItem with graphics.DrawString() for example
	*/
	graphics.DrawString(item.Progress + "% " + item.State, cellStyle.Font, new SolidBrush(cellStyle.ForeColor), cellBounds, stringFormat);
}

Basically, I created my custom column(and cell) with DataPropertyName set to "Progress" then I totally ignore the fact that the column "subscribes" to the Progress property and display whatever I want in the overridden Paint method Wink | ;)

Even though this works, I am interested in how you people would have solved it Smile | :)

modified 30-Nov-14 14:04pm.

QuestionLink-grammar 5.1.3 /Windows, MSVC Pin
Member 1127414829-Nov-14 18:07
Member 1127414829-Nov-14 18:07 
AnswerRe: Link-grammar 5.1.3 /Windows, MSVC Pin
Garth J Lancaster29-Nov-14 19:06
professionalGarth J Lancaster29-Nov-14 19:06 
QuestionHow to Handle Redirects to Login When Trying to Read Results From HttpWebRequest? Pin
Member 1127231728-Nov-14 15:29
Member 1127231728-Nov-14 15:29 
Questionsetting file's security to 'no delete' in code ? Pin
BillWoodruff28-Nov-14 8:39
professionalBillWoodruff28-Nov-14 8:39 
QuestionRe: setting file's security to 'no delete' in code ? Pin
Eddy Vluggen28-Nov-14 8:54
professionalEddy Vluggen28-Nov-14 8:54 
AnswerRe: setting file's security to 'no delete' in code ? Pin
BillWoodruff28-Nov-14 14:11
professionalBillWoodruff28-Nov-14 14:11 
GeneralRe: setting file's security to 'no delete' in code ? Pin
Eddy Vluggen1-Dec-14 8:02
professionalEddy Vluggen1-Dec-14 8:02 
GeneralRe: setting file's security to 'no delete' in code ? Pin
Manfred Rudolf Bihy1-Dec-14 9:01
professionalManfred Rudolf Bihy1-Dec-14 9:01 
AnswerRe: setting file's security to 'no delete' in code ? Pin
Dave Kreskowiak28-Nov-14 10:24
mveDave Kreskowiak28-Nov-14 10:24 
GeneralRe: setting file's security to 'no delete' in code ? Pin
BillWoodruff28-Nov-14 14:12
professionalBillWoodruff28-Nov-14 14:12 
AnswerRe: [still unsolved as of Dec. 1] setting file's security to 'no delete' in code ? Pin
Manfred Rudolf Bihy1-Dec-14 2:02
professionalManfred Rudolf Bihy1-Dec-14 2:02 
AnswerRe: [still unsolved as of Dec. 1] setting file's security to 'no delete' in code ? Pin
Manfred Rudolf Bihy1-Dec-14 3:01
professionalManfred Rudolf Bihy1-Dec-14 3:01 
GeneralRe: [still unsolved as of Dec. 1] setting file's security to 'no delete' in code ? Pin
BillWoodruff1-Dec-14 21:12
professionalBillWoodruff1-Dec-14 21:12 
GeneralRe: [still unsolved as of Dec. 1] setting file's security to 'no delete' in code ? Pin
Manfred Rudolf Bihy2-Dec-14 18:44
professionalManfred Rudolf Bihy2-Dec-14 18:44 
GeneralRe: [still unsolved as of Dec. 1] setting file's security to 'no delete' in code ? Pin
Manfred Rudolf Bihy3-Dec-14 21:17
professionalManfred Rudolf Bihy3-Dec-14 21:17 
QuestionWrite to Registry with Administrative Privileges Pin
Jassim Rahma28-Nov-14 1:36
Jassim Rahma28-Nov-14 1:36 
AnswerRe: Write to Registry with Administrative Privileges Pin
Richard MacCutchan28-Nov-14 2:50
mveRichard MacCutchan28-Nov-14 2:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.