C#實(shí)現(xiàn)給DevExpress中GridView表格指定列添加進(jìn)度條_第1頁(yè)
C#實(shí)現(xiàn)給DevExpress中GridView表格指定列添加進(jìn)度條_第2頁(yè)
C#實(shí)現(xiàn)給DevExpress中GridView表格指定列添加進(jìn)度條_第3頁(yè)
C#實(shí)現(xiàn)給DevExpress中GridView表格指定列添加進(jìn)度條_第4頁(yè)
C#實(shí)現(xiàn)給DevExpress中GridView表格指定列添加進(jìn)度條_第5頁(yè)
已閱讀5頁(yè),還剩2頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第C#實(shí)現(xiàn)給DevExpress中GridView表格指定列添加進(jìn)度條目錄一、問(wèn)題描述二、實(shí)現(xiàn)方法2.1、先注冊(cè)單元格繪制方法2.2、編寫(xiě)給指定單元格繪制進(jìn)度條的方法2.3、使用給指定單元格繪制進(jìn)度條方法三、相關(guān)內(nèi)容3.1、給單元格設(shè)置百分比

一、問(wèn)題描述

在我們使用Winform配合DevExpress進(jìn)行開(kāi)發(fā)表格時(shí),表格中的涉及到百分比數(shù)據(jù)的內(nèi)容除了顯示百分比的數(shù)字內(nèi)容外,還希望搭配顯示進(jìn)度條效果(且低于百分之60的內(nèi)容用紅色表示不合格,高于百分之60的用綠色表示),這樣百分比的顯示效果更加清晰直觀。

二、實(shí)現(xiàn)方法

2.1、先注冊(cè)單元格繪制方法

2.2、編寫(xiě)給指定單元格繪制進(jìn)度條的方法

#region給表格指定列繪制進(jìn)度條

///summary

///給指定列繪制進(jìn)度條

////summary

///paramname="gridView"GridView控件/param

///paramname="columnFieldName"需繪制進(jìn)度條列的字段名稱/param

///paramname="warningValue"警告值(用于區(qū)分不同的顏色)/param

///paramname="beforeWaringValueColor"警告值前的進(jìn)度條顏色/param

///paramname="afterWaringValueColor"警告值后的進(jìn)度條顏色/param

publicstaticvoidDrawProgressBarToColumn(DevExpress.XtraGrid.Views.Grid.GridViewgridView,stringcolumnFieldName,

doublewarningValue=60,BrushbeforeWaringValueColor=null,BrushafterWaringValueColor=null)

varcolumn=gridView.Columns[columnFieldName];

if(column==null)return;

column.AppearanceCell.Options.UseTextOptions=true;

//設(shè)置該列顯示文本內(nèi)容的位置(這里默認(rèn)居中)

column.AppearanceCell.TextOptions.HAlignment=HorzAlignment.Center;

//繪制事件方法(前提需要先注冊(cè)才能夠接收到參數(shù)使用)

gridView.CustomDrawCell+=(s,e)=

if(e.Column.FieldName==columnFieldName)

DrawProgressBar(e,warningValue,beforeWaringValueColor,afterWaringValueColor);

e.Handled=true;

DrawEditor(e);

///summary

///繪制進(jìn)度條

////summary

///paramname="e"單元格繪制事件參數(shù)/param

///paramname="warningValue"警告值(用于區(qū)分不同的顏色)/param

///paramname="beforeWaringValueColor"警告值前的進(jìn)度條顏色/param

///paramname="afterWaringValueColor"警告值后的進(jìn)度條顏色/param

publicstaticvoidDrawProgressBar(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgse,doublewarningValue=60,

BrushbeforeWaringValueColor=null,BrushafterWaringValueColor=null)

stringtmpValue=e.CellValue.ToString();

floatpercent=0;

if(!string.IsNullOrEmpty(tmpValue))

float.TryParse(tmpValue,outpercent);

intwidth=0;

if(percent2)

width=(int)(Math.Abs(percent/100)*e.Bounds.Width);

else

width=(int)(Math.Abs(percent)*e.Bounds.Width);

Rectanglerect=newRectangle(e.Bounds.X,e.Bounds.Y,width,e.Bounds.Height);

Brushb=Brushes.Green;

if(afterWaringValueColor!=null)

b=afterWaringValueColor;

if(percentwarningValue)

if(beforeWaringValueColor==null)

b=Brushes.Red;

else

b=beforeWaringValueColor;

e.Graphics.FillRectangle(b,rect);

///summary

///繪制單元格

////summary

///paramname="e"單元格繪制事件參數(shù)/param

publicstaticvoidDrawEditor(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgse)

DevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfocell=e.CellasDevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfo;

Pointoffset=cell.CellValueRect.Location;

DevExpress.XtraEditors.Drawing.BaseEditPainterpb=cell.ViewInfo.PainterasDevExpress.XtraEditors.Drawing.BaseEditPainter;

AppearanceObjectstyle=cell.ViewInfo.PaintAppearance;

if(!offset.IsEmpty)

cell.ViewInfo.Offset(offset.X,offset.Y);

pb.Draw(newDevExpress.XtraEditors.Drawing.ControlGraphicsInfoArgs(cell.ViewInfo,e.Cache,cell.Bounds));

finally

if(!offset.IsEmpty)

cell.ViewInfo.Offset(-offset.X,-offset.Y);

#endregion

2.3、使用給指定單元格繪制進(jìn)度條方法

注意:在使用給指定單元格繪制進(jìn)度條方法時(shí)(如果數(shù)字都是小于1的那么警告值也是需要小于1;如果是大于1的則按照需要設(shè)置即可)。

使用方法語(yǔ)法

DrawProgressBarToColumn(gridView組件名稱,需要繪制進(jìn)度條的單元格字段,警告值,警告值前的進(jìn)度條顏色,警告值后的進(jìn)度條顏色);

示例1

DrawProgressBarToColumn(gridView1,"Age",0.6,Brushes.OrangeRed,Brushes.LawnGreen);

示例2

DrawProgressBarToColumn(gridView1,"Age",0.6,newSolidBrush(Color.FromArgb(236,65,65)),newSolidBrush(Color.FromArgb(45,115,186)));

三、相關(guān)內(nèi)容

3.1、給單元格設(shè)置百分比

///summary

///設(shè)置表格指定單元格都使用百分比

////summary

///paramname="gridView"gridView組件/param

///paramname="columnName"列名稱/param

publicstaticvoidSetPercentage(GridViewgridView,stringcolumnName)

if(gridView!=nullgridView.Columns.Count0!string.IsNullOrEmpty(columnName))

gridView.Columns[columnName].DisplayFormat.FormatType=FormatType.Numeric;

gridView.Columns[columnName].DisplayFormat.FormatString="P2";

上面這個(gè)代碼實(shí)現(xiàn)的是將小數(shù)轉(zhuǎn)為百分比顯示【比如將小數(shù)(0.3)使用后就轉(zhuǎn)為(30%)顯示】

///summary

///給表格指定單元格都保留2位小數(shù)后添加%號(hào)

////summary

///paramname="gridView"/param

///paramname="startColumnIndex"/param

///paramname="endColumnIndex"/param

publicstaticvoidSetResreserveTwoBitAndPercentageChar(GridViewgridView,intstartColumnIndex,intendColumnIndex)

if(gridView!=nullgridView.Columns.Count0

startColumnIndex0endColumnIndex0

endColumnIndex=gridView.Columns.Count)

for(inti=startColumnIndex;i=endColumnIndex;i++)

gridView.Columns[i].DisplayFormat.

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論