//c1TrueDBGrid 選擇checkbox以後發生事件
private void c1TrueDBGrid1_AfterColEdit(object sender, C1.Win.C1TrueDBGrid.ColEventArgs e)
{
for (int i = 0; i < c1TrueDBGrid1.Splits[0].Rows.Count; i++)
{
if (c1TrueDBGrid1[i, "pState"].ToString() == "True")
a += decimal.Parse(c1TrueDBGrid1[i, "pMoney"].ToString());
}
}
(1) // 設定某列的是否顯示
this.c1TrueDBGrid1.Splits[0].DisplayColumns["fieldName"].Visible = false;
(2) //c1TrueDBGrid 獲得目前行數
int rows = this.c1TrueDBGrid2.Splits[0].Rows.Count;
(3)//c1TrueDBGrid 合計的做法
.寫在load事件裡的代碼
int rows = this.c1TrueDBGrid1.Splits[0].Rows.Count;
int sum1 = 0;
for (int i = 0; i < rows; i++)
{
string unit1 = this.c1TrueDBGrid1[i, "aa"].ToString();
sum1 += Convert.ToInt32(unit1);
}
this.c1TrueDBGrid1.Columns["aa"].FooterText = sum1.ToString();
.c1TrueDBGrid1屬性ColumnFooters設定為true
或者在load中加上 c1TrueDBGrid1.ColumnFooters = true;(截止)
(4) /// c1TrueDBGrid /設定某一列的背景顏色
this.c1TrueDBGrid1.Splits[0].DisplayColumns["bb"].Style.BackColor = System.Drawing.Color.Blue;
(5) // c1TrueDBGrid 設定某一列不允許取得焦點
this.c1TrueDBGrid1.Splits[0].DisplayColumns["bb"].AllowFocus = false;
(6) // c1TrueDBGrid 設定某一列不不能編輯
this.c1TrueDBGrid1.Splits[0].DisplayColumns["bb"].Locked = true;
(7) //c1TrueDBGrid 某一列的寬度設定為自適應寬度
this.c1TrueDBGrid1.Splits[0].DisplayColumns["aa"].AutoSize();
(8) //c1TrueDBGrid 凍結某一列
this.c1TrueDBGrid1.Splits[0].DisplayColumns["aa"].Frozen = true;
(9) 設定資料庫狀態。和CheckBox運用
(10) c1TrueDBGrid1設定綁定顏色設定[小於0顯示紅色]
private void c1TrueDBGrid1_FetchRowStyle(object sender, C1.Win.C1TrueDBGrid.FetchRowStyleEventArgs e)
{
if (c1TrueDBGrid1[e.Row, "bWnum"] != null)
{
//兩種取值方法是一樣的
int intTmp = int.Parse(c1TrueDBGrid1[e.Row, "bWnum"].ToString());
if (intTmp < 0)
{
e.CellStyle.BackColor = Color.Red;
}
}
}
C1.Win.C1TrueDBGrid.ValueItems items = this.c1TrueDBGrid1.Columns["Status"].ValueItems;
items.Translate = true;
items.CycleOnClick = true;
items.Presentation = C1.Win.C1TrueDBGrid.PresentationEnum.CheckBox;
items.Values.Clear();
items.Values.Add(new C1.Win.C1TrueDBGrid.ValueItem("0", false)); // unchecked
items.Values.Add(new C1.Win.C1TrueDBGrid.ValueItem("1", true)); // checked
(11)C1TrueDBGrid 資料行繫結下拉式功能表的實現代碼,,還需要在C1TrueDbGrid列設計器裡將的Translate屬性設定為true,它是一個子屬性
DataTable dt = new DataTable();
dt.Columns.Add("ColumnName", typeof(string));//欄位名
dt.Columns.Add("Compare", typeof(string));//比較
dt.Columns.Add("Values", typeof(string));//值
dt.Columns.Add("Logic", typeof(string));//邏輯
c1TrueDBGrid1.DataSource = dt;
BLL.SetCaptionNoInnerID(c1TrueDBGrid1, "欄位名|比較|值|邏輯");
C1.Win.C1TrueDBGrid.ValueItems item = this.c1TrueDBGrid1.Columns["ColumnName"].ValueItems;
item.Translate = true;
item.Presentation = C1.Win.C1TrueDBGrid.PresentationEnum.ComboBox;
item.Values.Clear();
foreach (DataRow row in colDT.Rows)
{
item.Values.Add(new C1.Win.C1TrueDBGrid.ValueItem(row["name"].ToString(), row["value"].ToString()));
}
c1TrueDBGrid1.Splits[0].DisplayColumns["ColumnName"].Locked = false;//設定可編輯
(12)
c1TrueDBGrid1列的合并 c1TrueDBGrid1.Splits[0].DisplayColumns["Batch"].Merge = true;