#region dataGridView1顯示行號
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
dataGridView1.RowHeadersWidth - 4,
e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
dataGridView1.RowHeadersDefaultCellStyle.Font,
rectangle,
dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
#endregion
在dataGridView1的RowPostPaint事件中,選擇dataGridView1_RowPostPaint函數
2009年8月19日 星期三
2009年8月18日 星期二
動態修改ComboBox選項寬度
ComboBox senderComboBox = (ComboBox)sender;
int width = senderComboBox.DropDownWidth;
Graphics g = senderComboBox.CreateGraphics();
Font font = senderComboBox.Font;
int vertScrollBarWidth =
(senderComboBox.Items.Count>senderComboBox.MaxDropDownItems)
?SystemInformation.VerticalScrollBarWidth:0;
int newWidth;
foreach (string s in ((ComboBox)sender).Items)
{
newWidth = (int) g.MeasureString(s, font).Width
+ vertScrollBarWidth;
if (width < newWidth )
{
width = newWidth;
}
}
senderComboBox.DropDownWidth = width;
2009年8月12日 星期三
ReportViewer 切換至預覽列印模式
1. 用ReportView的SetDisplayMode方法 將顯示模式切換至PrintLayout(列印預覽);
2. 在 [列印預覽] 模式中,[縮放] 下拉式清單預設選項是 [整頁]。因此切換ZoomMode屬性為Percent,
並設定ZoomPercent屬性為100;
程式碼如下:
using Microsoft.Reporting.WinForms;(引命名空間)
private void CouponPrint_Load(object sender, EventArgs e)
{
{
//以列印模式顯示
this.reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
this.reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
//切換縮放方式為百分比 - 100%
this.reportViewer1.ZoomMode = ZoomMode.Percent;
this.reportViewer1.ZoomPercent = 100;
this.reportViewer1.ZoomMode = ZoomMode.Percent;
this.reportViewer1.ZoomPercent = 100;
}
2009年8月4日 星期二
Report View 傳入參數
Dim AR(2) As ReportParameter
AR(0) = New ReportParameter("REPORT_TITLE", "報表標題")
AR(1) = New ReportParameter("Para1", "1")
AR(2) = New ReportParameter("Para2", "2")
ReportViewer1.LocalReport.SetParameters(AR)
動態修改RDLC的資料來源
dim cnn As New SqlConnection(ConfigurationManager.ConnectionStrings("AdventureWorksConnectionString").ConnectionString)
3 Dim cmd As New SqlCommand("SELECT * FROM HumanResources.Employee WHERE MaritalStatus='S'", cnn)
4 Dim da As New SqlDataAdapter(cmd)
5 '將動態Select出來的資料填入Datatable當資料來源
6 Dim dt As New DataTable
7 da.Fill(dt)
8 '將ReportViewer1的DataSources集合清除
9 ReportViewer1.LocalReport.DataSources.Clear()
10 '然後重新新增一個名稱為"AdventureWorksDataSet_Employee"的ReportDataSource給ReportViewer1
11 ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("AdventureWorksDataSet_Employee", dt))
12 ReportViewer1.LocalReport.Refresh()
3 Dim cmd As New SqlCommand("SELECT * FROM HumanResources.Employee WHERE MaritalStatus='S'", cnn)
4 Dim da As New SqlDataAdapter(cmd)
5 '將動態Select出來的資料填入Datatable當資料來源
6 Dim dt As New DataTable
7 da.Fill(dt)
8 '將ReportViewer1的DataSources集合清除
9 ReportViewer1.LocalReport.DataSources.Clear()
10 '然後重新新增一個名稱為"AdventureWorksDataSet_Employee"的ReportDataSource給ReportViewer1
11 ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("AdventureWorksDataSet_Employee", dt))
12 ReportViewer1.LocalReport.Refresh()
訂閱:
意見 (Atom)