hi allata
If I only have this piece of data can i know the header Text of the datagridview column
//---------------------------
g.DrawString( TheDataGridView.Rows[CurrentRow].Cells[CurrentCell].EditedFormattedValue.ToString(), RowFont, RowForeBrush, CellBounds, CellFormat);
//-------------------------
tq
han
Loading

Sam HobbsRank #108 · 20.5K reputationPosted Dec 18, 2009, 6:38 AM EST
hanafi tanudjaja41 reputationPosted Dec 18, 2009, 3:56 PM EST
in my question context I have tried"
//-------------------------------------------------
if (TheDataGridView.Rows[CurrentRow].Cells[CurrentCell].Header.Text=="City")
{
}
and again
if (TheDataGridView.Rows[CurrentRow].Cells[CurrentCell].EditedFormattedValue.Header.Text=="City")
{
{
both of the are not working
any help ?
tg
}
//-----------------------------------------------
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Dec 20, 2009, 9:17 PM EST
Use following code.
if ((TheDataGridView.CurrentCell.OwningColumn.HeaderText == "City")
{
}
If you find my answer useful, please check 'Do you like this answer' checkbox.
hanafi tanudjaja41 reputationPosted Dec 21, 2009, 2:06 PM EST
Ihave tried your suggestion ,but still doesn work.
I insert
//--------------------------------
if ((TheDataGridView.CurrentCell.OwningColumn.HeaderText == "City")
{
MessageBox.Show("This is the column ");
}
//-----------------------------------
but no messageBox Shown ,the column with the header text "City" is available
thank you and regard
hanafi
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Dec 21, 2009, 5:59 PM EST
where did you place thie code block. If you select a cell in city column you should get the message box.But for that, you should place this code block inside cellclick event of datagridview. If you can upload your code, I can correct it.
hanafi tanudjaja41 reputationPosted Dec 21, 2009, 8:08 PM EST
here is the snippet of code,I get it from ia site and try to make little change for my own need.
I suppose the iteration loop is from leftmost cell to the rightmost
thank you and nice regard
btw you have nice to hear name
//-----------------
for (int CurrentCell = (int)mColumnPoints[mColumnPoint].GetValue(0);
CurrentCell < (int)mColumnPoints[mColumnPoint].GetValue(1);
CurrentCell++)
{
// If the cell is belong to invisible
// column, then ignore this iteration
if (!TheDataGridView.Columns[CurrentCell].Visible) continue;
// Check the CurrentCell alignment
// and apply it to the CellFormat
if (TheDataGridView.Columns[CurrentCell].DefaultCellStyle.
Alignment.ToString().Contains("Right"))
CellFormat.Alignment = StringAlignment.Far;
else if (TheDataGridView.Columns[CurrentCell].DefaultCellStyle.
Alignment.ToString().Contains("Center"))
CellFormat.Alignment = StringAlignment.Center;
else
CellFormat.Alignment = StringAlignment.Near;
ColumnWidth = ColumnsWidth[CurrentCell];
RectangleF CellBounds = new RectangleF(CurrentX, CurrentY,
ColumnWidth, RowsHeight[CurrentRow]);
//int intx = TheDataGridView.CurrentCell.ColumnIndex;
//if (intx==1)
//{
// MessageBox.Show("1");
//}
g.DrawString(
TheDataGridView.Rows[CurrentRow].Cells[CurrentCell].
EditedFormattedValue.ToString(), RowFont, RowForeBrush,
CellBounds, CellFormat);
////// I put the addition in here ---------------------not " CITy" i am looking for but "JUMLAH" ////---------------
if (TheDataGridView.CurrentCell.OwningColumn.HeaderText == "JUMLAH")
{
MessageBox.Show("Header=Jumlah");
}
///////--------------------------------------------------
// Drawing the cell bounds
// Draw the cell border only
// if the CellBorderStyle is not None
if (TheDataGridView.CellBorderStyle !=
DataGridViewCellBorderStyle.None)
g.DrawRectangle(TheLinePen, CurrentX, CurrentY,
ColumnWidth, RowsHeight[CurrentRow]);
CurrentX += ColumnWidth;
}
//------------------------------------
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Dec 21, 2009, 9:05 PM EST
I'm sorry. Your code is still not clear for me. Can you upload your project? If it is too big, then at least paste or upload the code of the whole class.
Then I'll help you for sure.
hanafi tanudjaja41 reputationPosted Dec 21, 2009, 9:55 PM EST
I feel very sorry to make you busy
I also feel afraid to bother others by sending large file to this site ,so I think better to point the site
which launch the class:
it is in
http://www.codeproject.com/KB/printing/datagridviewprinter.aspx?msg=2279275#xx2279275xx
thank you & best regard
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Dec 21, 2009, 11:44 PM EST
I got your problem. Add this code.
if (TheDataGridView.Rows[CurrentRow].Cells[CurrentCell].OwningColumn.HeaderText.Equals("JUMLAH"))
{
MessageBox.Show("Header=Jumlah");
}
Please tick 'Do you like this answer' checkbox if this helps you.
hanafi tanudjaja41 reputationPosted Dec 22, 2009, 2:35 AM EST
,sorry to tell u that still not work,no error ,but no messagebox.arise
but never mind ,for this moment i use My own much more simple way but works
just to display the database, goods quantiy (JUMLAH=qty),and goods total quantity.
thank & regard