!!!急!!!!datagrid 有关问题(winform)

tinyghost 2003-04-01 01:23:54
制作在winform下datagrid程序,我利用textcol.textbox的passwordchar属性设置一列显现为密码列,问题是设置完成之后还是以原来的形式显示,而不显示类似*的字样.我将一列扩展成combox,然后将数据binding,但是为什么显示是valuemember的内容而不是displaymember的内容,这个如何解决.
我先在程序建立数据源,然后设置每列的style属性,然后binging数据源,我还需要对datagrid进行别的操作么??
...全文
25 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tinyghost 2003-04-02
  • 打赏
  • 举报
回复
哪位帮忙解决一下?
tinyghost 2003-04-02
  • 打赏
  • 举报
回复
namespace app
{
/// <summary>
/// Form4 的摘要说明。
/// </summary>
public class frm_user : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private DataSet myDataSet,myDataSet_group;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public frm_user()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//设计DataGrid 形式为combox
MakeComboxGrid();
//
dataGrid1.DataSource=myDataSet.Tables["RightUser"];
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
private void MakeComboxGrid()
{
//制造数据集////////////
MakeDataSet();

//制造列形式//////
AddTableStyle();


}
private void MakeDataSet()
{
///////////////////////创建用户信息数据集
SqlConnection myConn = new SqlConnection(LoginData.ConnectString);
string selectstring ="SELECT userid,username,password,rightgroup from U_RIGHTUSER ";
SqlCommand myComm = myConn.CreateCommand();
myComm.CommandText=selectstring;
SqlDataAdapter myAdap = new SqlDataAdapter();
myAdap.SelectCommand = myComm;
//生成数据集
myConn.Open();
string DataTableName ="RightUser";
myDataSet = new DataSet("myDataSet");
myAdap.Fill(myDataSet,DataTableName);
myConn.Close();
//DataTable myDataTable = myDataSet.Tables[DataTableName];
////////////创建组权限数据集/////////
SqlConnection myConn_group = new SqlConnection(LoginData.ConnectString);
string selectgroupstring = "SELECT group_id,group_name,group_text from U_RIGHTGROUP";
SqlCommand myComm_group = myConn_group.CreateCommand();
myComm_group.CommandText = selectgroupstring;
SqlDataAdapter myAdap_group = new SqlDataAdapter();
myAdap_group.SelectCommand = myComm_group;
myConn_group.Open();
string DataTableName_group = "RightGroup";
myDataSet_group = new DataSet("myDataSet_group");
myAdap_group.Fill(myDataSet_group,DataTableName_group);
myConn_group.Close();
}
private void AddTableStyle()
{
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "RightUser";
// Set other properties.
ts1.AlternatingBackColor = Color.LightGray;
//
// Add 2 cols with textbox column style
DataGridTextBoxColumn TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "userid";
TextCol.HeaderText = "用户编号";
TextCol.ReadOnly = true;
TextCol.Width = 120;
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "username";
TextCol.HeaderText = "用户姓名";
TextCol.ReadOnly = true;
TextCol.Width = 120;
ts1.GridColumnStyles.Add(TextCol);

TextCol = new DataGridTextBoxColumn();
TextCol.MappingName = "password";
TextCol.HeaderText = "用户密码";
TextCol.TextBox.PasswordChar = '*';
TextCol.ReadOnly = true;
TextCol.Width = 120;
ts1.GridColumnStyles.Add(TextCol);
//*******************************************// the main idea
// Step 2 - Use the combo column style
// Add 1 col with combo style
DataGridComboBoxColumn ComboTextCol = new DataGridComboBoxColumn(new ComboValueChanged(MyComboValueChanged));
ComboTextCol.MappingName = "rightgroup";
ComboTextCol.HeaderText = "用户权限";
ComboTextCol.Width = 200;
ts1.GridColumnStyles.Add(ComboTextCol);
ts1.PreferredRowHeight = ComboTextCol.ColumnComboBox.Height + 3;
ComboTextCol.ColumnComboBox.DataSource = myDataSet_group.Tables["RightGroup"];
ComboTextCol.ColumnComboBox.DisplayMember = "group_name";
ComboTextCol.ColumnComboBox.ValueMember = "group_id";
//ComboTextCol.ColumnComboBox.Items.Clear();
//ComboTextCol.ColumnComboBox.Items.Add("Chicago");
ComboTextCol.ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
dataGrid1.TableStyles.Add(ts1);
}

public void MyComboValueChanged(int rowChanging, object newValue)
{
Console.WriteLine("index changed {0} {1}", rowChanging, newValue);
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(592, 273);
this.dataGrid1.TabIndex = 0;
//
// frm_user
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(592, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.dataGrid1});
this.Name = "frm_user";
this.Text = "操作员录入";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion
}
}
tinyghost 2003-04-02
  • 打赏
  • 举报
回复
代码在下面
nchln 2003-04-01
  • 打赏
  • 举报
回复
看看代码

110,538

社区成员

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

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

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