Click here to Skip to main content
15,909,605 members
Home / Discussions / Article Writing
   

Article Writing

 
AnswerRe: Pleasr help me! Pin
Pete O'Hanlon2-Oct-07 10:40
mvePete O'Hanlon2-Oct-07 10:40 
GeneralRe: Pleasr help me! Pin
originSH2-Oct-07 22:32
originSH2-Oct-07 22:32 
AnswerRe: Pleasr help me! Pin
Paul Conrad3-Nov-07 7:56
professionalPaul Conrad3-Nov-07 7:56 
QuestionPleasr help me! I'm very worried now! Pin
today422001-Oct-07 22:07
today422001-Oct-07 22:07 
AnswerRe: Pleasr help me! I'm very worried now! Pin
Jonathan [Darka]12-Oct-07 3:59
professionalJonathan [Darka]12-Oct-07 3:59 
AnswerRe: Pleasr help me! I'm very worried now! Pin
Pete O'Hanlon14-Oct-07 9:55
mvePete O'Hanlon14-Oct-07 9:55 
AnswerRe: Pleasr help me! I'm very worried now! Pin
Paul Conrad3-Nov-07 7:57
professionalPaul Conrad3-Nov-07 7:57 
QuestionQuestion from the article Multi Column Combo Cell C#, hoping for author to help! Pin
quakertistar30-Sep-07 5:01
quakertistar30-Sep-07 5:01 
I've tried so hard for a whole day that I still cannot get through this tough problem, somebody please, help me!



I've got the code for Multi Column Combo in DataGridView to solve the problem of displaying multiple data, but I got stuck in displaying some values. Everything goes just fine, but when I tried to display values with the key value diplicated, it doesn't work. For example, I intended to display two rows "bmx2100 |23455 |34" and "bmx2100 |11111 |100", they have the same attribute "bmx2100", but the primary key "23455" and "11111" are different. That was what suppose to be, but now, the program displayed "bmx2100 |23455 |34" twice, and during DEBUG, I print out all the temporary variables and I found that they are all correct! So, what would be the problem!?



This is the Multi Column Combo Cell : http://www.codeproject.com/useritems/Multi_Column_Combo_Cell.asp



And this is the code snippet I modified:




protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)<br />
{<br />
Rectangle rec = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);<br />
DataGridViewMultiColumnComboColumn column = ownerCell.OwningColumn as DataGridViewMultiColumnComboColumn;<br />
DataTable valuesTbl = column.valuesTbl;<br />
string joinByField = column.joinFieldName;<br />
SolidBrush NormalText = new SolidBrush(System.Drawing.SystemColors.ControlText);<br />
object currentItem = Items[e.Index];<br />
string currentText = GetItemText(currentItem);<br />
<br />
//If there is an item<br />
if (e.Index > -1)<br />
{<br />
//first redraw the normal while background<br />
SolidBrush normalBack = new SolidBrush(Color.White); //TODO: fix to be system edit box background<br />
e.Graphics.FillRectangle(normalBack, rec);<br />
if (DroppedDown && !(Margin.Top == rec.Top))<br />
{<br />
int currentOffset = rec.Left;<br />
<br />
//now find this text corrent join field<br />
DataRow[] itemRows = valuesTbl.Select("[" + joinByField + "]='" + currentText + "'");<br />
<br />
SolidBrush HightlightedBack = new SolidBrush(System.Drawing.SystemColors.Highlight);<br />
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)<br />
{<br />
//draw selected color background<br />
e.Graphics.FillRectangle(HightlightedBack, rec);<br />
}<br />
StreamWriter sw = new StreamWriter(File.OpenWrite("record"));<br />
foreach (DataRow currentRow in itemRows)<br />
{<br />
bool addBorder = false;<br />
<br />
foreach (object dataRowItem in currentRow.ItemArray)<br />
{<br />
string value = dataRowItem.ToString(); //TODO: support for different types!!!<br />
<br />
<br />
<br />
#region DrawLine<br />
if (addBorder)<br />
{<br />
//draw dividing line<br />
//currentOffset ++; <br />
SolidBrush gridBrush = new SolidBrush(Color.Gray); //TODO: make the border color configurable<br />
long linesNum = lineWidth;<br />
while (linesNum > 0)<br />
{<br />
linesNum--;<br />
Point first = new Point(rec.Left + currentOffset, rec.Top);<br />
Point last = new Point(rec.Left + currentOffset, rec.Bottom);<br />
e.Graphics.DrawLine(new Pen(gridBrush), first, last);<br />
currentOffset++;<br />
}<br />
//currentOffset++;<br />
}<br />
else<br />
addBorder = true;<br />
#endregion<br />
<br />
//measure the string that we are goin to draw and cut it with wrapping if too large<br />
SizeF extent = e.Graphics.MeasureString(value, e.Font);<br />
Rectangle textRec = new Rectangle(currentOffset, rec.Y, (int)extent.Width + 20, rec.Height);<br />
<br />
//now draw the relevant to this column value text<br />
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)<br />
{<br />
//draw selected<br />
SolidBrush HightlightedText = new SolidBrush(System.Drawing.SystemColors.HighlightText);<br />
//now redraw the backgrond it order to wrap the previous field if was too large<br />
e.Graphics.FillRectangle(HightlightedBack, currentOffset, rec.Y, fixedAlignColumnSize, extent.Height);<br />
//draw text as is <br />
e.Graphics.DrawString(value, e.Font, HightlightedText, textRec); sw.Write(value + "|");<br />
}<br />
else<br />
{<br />
//now redraw the backgrond it order to wrap the previous field if was too large<br />
e.Graphics.FillRectangle(normalBack, currentOffset, rec.Y, fixedAlignColumnSize, extent.Height);<br />
//draw text as is <br />
e.Graphics.DrawString(value, e.Font, NormalText, textRec); sw.Write(value + "|");<br />
}<br />
//advance the offset to the next position<br />
currentOffset += fixedAlignColumnSize;<br />
}<br />
sw.WriteLine();<br />
}<br />
sw.Close();<br />
}<br />
else<br />
//if happens when the combo is closed, draw single standard item view<br />
e.Graphics.DrawString(currentText, e.Font, NormalText, rec);<br />
}<br />
}<br />
/**************************************************************************************************/<br />
}

AnswerRe: Question from the article Multi Column Combo Cell C#, hoping for author to help! Pin
Scott Dorman30-Sep-07 8:24
professionalScott Dorman30-Sep-07 8:24 
GeneralRe: Question from the article Multi Column Combo Cell C#, hoping for author to help! Pin
quakertistar1-Oct-07 3:20
quakertistar1-Oct-07 3:20 
GeneralRe: Question from the article Multi Column Combo Cell C#, hoping for author to help! Pin
Scott Dorman1-Oct-07 3:33
professionalScott Dorman1-Oct-07 3:33 
GeneralRe: Question from the article Multi Column Combo Cell C#, hoping for author to help! Pin
quakertistar1-Oct-07 3:45
quakertistar1-Oct-07 3:45 
GeneralRe: Question from the article Multi Column Combo Cell C#, hoping for author to help! Pin
Scott Dorman1-Oct-07 4:02
professionalScott Dorman1-Oct-07 4:02 
GeneralRe: Question from the article Multi Column Combo Cell C#, hoping for author to help! Pin
quakertistar1-Oct-07 4:16
quakertistar1-Oct-07 4:16 
GeneralRe: Question from the article Multi Column Combo Cell C#, hoping for author to help! Pin
Pete O'Hanlon1-Oct-07 4:22
mvePete O'Hanlon1-Oct-07 4:22 
GeneralRe: Question from the article Multi Column Combo Cell C#, hoping for author to help! Pin
Scott Dorman1-Oct-07 15:55
professionalScott Dorman1-Oct-07 15:55 
GeneralRe: Question from the article Multi Column Combo Cell C#, hoping for author to help! Pin
Scott Dorman1-Oct-07 15:54
professionalScott Dorman1-Oct-07 15:54 
GeneralRe: Question from the article Multi Column Combo Cell C#, hoping for author to help! Pin
Pete O'Hanlon1-Oct-07 3:55
mvePete O'Hanlon1-Oct-07 3:55 
GeneralRe: Question from the article Multi Column Combo Cell C#, hoping for author to help! Pin
Scott Dorman1-Oct-07 4:02
professionalScott Dorman1-Oct-07 4:02 
Questionlive presentation in asp.net Pin
Barbis27-Sep-07 22:13
Barbis27-Sep-07 22:13 
AnswerRe: live presentation in asp.net Pin
Pete O'Hanlon30-Sep-07 23:34
mvePete O'Hanlon30-Sep-07 23:34 
AnswerRe: live presentation in asp.net Pin
Paul Conrad3-Nov-07 7:57
professionalPaul Conrad3-Nov-07 7:57 
QuestionHow to order/design the system Pin
Mri1a25-Sep-07 20:28
Mri1a25-Sep-07 20:28 
AnswerRe: How to order/design the system Pin
Pete O'Hanlon25-Sep-07 21:44
mvePete O'Hanlon25-Sep-07 21:44 
AnswerRe: How to order/design the system Pin
Paul Conrad3-Nov-07 7:57
professionalPaul Conrad3-Nov-07 7:57 

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.