DataGridStyle问题

flers 2005-06-27 05:13:30
AryBOC = busAdds.GetAddress(TreeparentId); //對象數組
if(AryBOC.Count>0)
{
dgMeans.TableStyles.Clear();
dgMeans.SetDataBinding(AryBOC,"");
DataGridTextBoxColumn modelColumn = new DataGridTextBoxColumn();
modelColumn.MappingName= "HierarchyName";
modelColumn.HeaderText= "ID號";


DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "ArrayList";
ts1.GridColumnStyles.Add(modelColumn);
dgMeans.TableStyles.Add(ts1);
}

1.這樣做一點變化都無呢??
2.我想在DATAGRID中新增CHECKBOX也無???
...全文
99 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
flers 2005-06-27
  • 打赏
  • 举报
回复
dgMeans.TableStyles.Clear();
dgMeans.DataSource = AryBOC;

DataGridTableStyle MachineTable = new DataGridTableStyle();
MachineTable.MappingName = "ArrayList";
DataGridTextBoxColumn modelColumn = new DataGridTextBoxColumn();

modelColumn.MappingName= "HierarchyName";
modelColumn.HeaderText= "名稱";
MachineTable.GridColumnStyles.Add(modelColumn);
dgMeans.TableStyles.Add(MachineTable);
flers 2005-06-27
  • 打赏
  • 举报
回复
还是不行
cchon 2005-06-27
  • 打赏
  • 举报
回复
我以前写的:
public class ComboBoxColumnStyle : System.Windows.Forms.DataGridColumnStyle
{
private System.Windows.Forms.ComboBox comboBox;
private bool isEditing = false;
private bool readOnly = true;


public ComboBoxColumnStyle() : base()
{
comboBox = new ComboBox();
comboBox.Visible = false;
isEditing = false;
}


public System.Windows.Forms.ComboBox ComboBox
{
get { return comboBox;}
set { comboBox = value;}
}

public string Text
{
get {return comboBox.Text;}
set {comboBox.Text = value;}
}


public override bool ReadOnly
{
get
{
return readOnly;
}
set
{
readOnly = value;
}
}



protected override void Abort(int rowNum)
{
isEditing = false;
}

protected override bool Commit(CurrencyManager dataSource, int rowNum)
{
this.comboBox.Bounds = Rectangle.Empty;

if (!isEditing)
{
return true;
}

isEditing = false;

try
{
string text = this.comboBox.Text;
SetColumnValueAtRow(dataSource, rowNum, text);
}
catch
{
Abort(rowNum);
return false;
}

Invalidate();
return true;
}

protected override int GetPreferredHeight(Graphics g, object value)
{
return comboBox.PreferredHeight;
}

protected override Size GetPreferredSize(
Graphics g,
object value)
{
return new Size(100, comboBox.PreferredHeight);
}


protected override int GetMinimumHeight()
{
return comboBox.PreferredHeight;
}


protected override void Edit(
CurrencyManager source,
int rowNum,
Rectangle bounds,
bool readOnly,
string instantText,
bool cellIsVisible)
{

DataGrid grid = DataGridTableStyle.DataGrid;
if (this.readOnly)
{
comboBox.Visible = false;
}
else
{
string text = GetColumnValueAtRow(source, rowNum).ToString();

comboBox.Text = text;
if (cellIsVisible)
{
comboBox.Bounds = new Rectangle(bounds.X , bounds.Y , bounds.Width, bounds.Height);
comboBox.Visible = true;
comboBox.Focus();
//comboBox.Select(textBox.Text.Length, 0);
}
else
{
comboBox.Visible = false;
}
if (comboBox.Visible)
{
DataGridTableStyle.DataGrid.Invalidate(bounds);
this.isEditing = true;
}
}

}


protected override void Paint(Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum)
{
Paint(g,bounds, source, rowNum, Brushes.Transparent, Brushes.Black, false);
}



protected override void Paint(
Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum,
bool alignToRight)
{
Paint(g,bounds, source,rowNum, Brushes.Transparent, Brushes.Black, alignToRight);
}


protected override void Paint(
Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum,
Brush backBrush,
Brush foreBrush,
bool alignToRight)
{
Rectangle rect = bounds;
g.FillRectangle(backBrush, rect);
//rect.X += 1;
//rect.Y += 2;
//rect.Height -= 2;
//rect.Width -= 1;
string text = GetColumnValueAtRow(source, rowNum).ToString();
//text = FormatShowText(text);
g.DrawString(text, this.DataGridTableStyle.DataGrid.Font, foreBrush, rect);

}




protected override void SetDataGridInColumn(DataGrid grid)
{

base.SetDataGridInColumn(grid);

if (comboBox.Parent != null)
{
comboBox.Parent.Controls.Remove(comboBox);
}
if (grid != null)
{
grid.Controls.Add(comboBox);
}
}


}
flers 2005-06-27
  • 打赏
  • 举报
回复
还是不行
thinkingforever 2005-06-27
  • 打赏
  • 举报
回复
DataGridBoolColumn

110,552

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧