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

tinyghost 2003-04-03 11:06:24
制作在winform下datagrid程序,我利用textcol.textbox的passwordchar属性设置一列显现为密码列,问题是设置完成之后还是以原来的形式显示,而不显示类似*的字样.我将一列扩展成combox,然后将数据binding,但是为什么显示是valuemember的内容而不是displaymember的内容,这个如何解决.
我先在程序建立数据源,然后设置每列的style属性,然后binging数据源,我还需要对datagrid进行别的操作么??
代码如下:
...全文
21 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tuzi98 2003-04-03
  • 打赏
  • 举报
回复
对不起,好象这样也不行
tuzi98 2003-04-03
  • 打赏
  • 举报
回复
你将要设密码的列这样
iconColumn.TextBox.Multiline = false; 就行
tinyghost 2003-04-03
  • 打赏
  • 举报
回复
public class frm_user : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private DataSet myDataSet,myDataSet_group;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public frm_user()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//设计DataGrid 形式为combox
MakeComboxGrid();
// DataView myDataView = new DataView(myDataSet.Tables["RightUser"]);
// dataGrid1.DataSource=myDataView;
// myDataView.RowFilter="userid='0000'";


//
dataGrid1.DataSource=myDataSet.Tables["RightUser"];
dataGrid1.Refresh();
// 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()
{
DataTable table = new DataTable();
table.TableName = myDataSet.Tables["RightUser"].ToString();
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = table.TableName;
// 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.PreferredRowHeight = ComboTextCol.ColumnComboBox.Height + 3;
ComboTextCol.ColumnComboBox.DataSource = myDataSet_group.Tables["RightGroup"];
ComboTextCol.ColumnComboBox.DisplayMember = "group_name";
ComboTextCol.ColumnComboBox.ValueMember = "group_id";
ComboTextCol.TextBox.Text=ComboTextCol.ColumnComboBox.DisplayMember;
//ComboTextCol.ColumnComboBox.Items.Clear();
//ComboTextCol.ColumnComboBox.Items.Add("Chicago");
ComboTextCol.ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
ts1.GridColumnStyles.Add(ComboTextCol);
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();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.CaptionVisible = false;
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;
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4,
this.menuItem5});
this.menuItem1.Text = "编辑";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "添加";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "删除";
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = "保存";
//
// menuItem5
//
this.menuItem5.Index = 3;
this.menuItem5.Text = "退出";
//
// 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;
this.Load += new System.EventHandler(this.frm_user_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);

}
#endregion

private void frm_user_Load(object sender, System.EventArgs e)
{

}

110,536

社区成员

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

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

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