dataGridView1在设计时如何调整列宽?

qcrsoft 2006-11-29 03:41:10
另外我想实现用户在使用时调整列列宽,下次再打开程序列每列的宽自动设置为用户关闭程序时的
状态,我目前是在窗口关闭时记录在注册表里,有更好的方法吗?
感激涕零!

(回贴光荣)
...全文
411 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
commonmj 2006-11-30
  • 打赏
  • 举报
回复
网上有下载的,搜索101sample,有关ClientConfiguration示例
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();

// Add a setting at runtime.
PrepareSettings();
}

private void Form1_Load(object sender, EventArgs e)
{
DisplayUser();
LoadSettings();
}

public void DisplayUser()
{
System.Security.Principal.WindowsIdentity currentUser = System.Security.Principal.WindowsIdentity.GetCurrent();
userIdentityTextBox.Text = currentUser.Name;
}

// Typically, Application and User settings will be
// defined at design time, in which case they are
// accessible via the strongly typed Settings class.
// But, it is possible to add settings programmatically,
// though they will not be saved with the
// Properties.Settings.Default.Properties.Save method call.
public void PrepareSettings()
{
// For dynamically added setings, make sure the setting doesn't
// exist already, for future proofing.
if ( Properties.Settings.Default.Properties["comboBoxDefaultSetting"] == null)
{
// Create a new setting.
SettingsProperty comboBoxDefaultSetting = new SettingsProperty("comboBoxDefaultSetting");
comboBoxDefaultSetting.PropertyType = typeof(String);
comboBoxDefaultSetting.DefaultValue = "Ipsum";
Properties.Settings.Default.Properties.Add(comboBoxDefaultSetting);
}
}

public void LoadSettings()
{
// Retrieve and set the location of the ToolStrips
ToolStripManager.LoadSettings(this);

// userBoolSetting was defined at design time using the Settings Designer window.
// So its value is available via the Settings class.
// Note the setting value is a boolean. Settings in
// Visual Studio 2005 are strongly typed, and support custom types and objects.
this.checkBox1.Checked = Properties.Settings.Default.userBoolSetting;

// comboBoxDefaultSetting was defined above, dynamically,
// and so it is not available in the Settings class.
// Must use Settings.Properties
this.comboBox1.SelectedIndex = this.comboBox1.FindStringExact(ClientConfiguration.Properties.Settings.Default.Properties["comboBoxDefaultSetting"].DefaultValue.ToString());

this.userStringTextBox.Text = Properties.Settings.Default.userStringSetting;
this.userIntNumPicker.Value = Properties.Settings.Default.userIntSetting;

this.appStringTextBox.Text = Properties.Settings.Default.appStringSetting;
this.appIntNumPicker.Value = Properties.Settings.Default.appIntSetting;
}

public void SaveSettings()
{
// Save the location of the ToolStrips
ToolStripManager.SaveSettings(this);

// Save changed settings
Properties.Settings.Default.Save();
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
SaveSettings();
}

private void saveUserPrefsButton_Click(object sender, EventArgs e)
{
SaveSettings();
}

private void setCheckBox1DefaultButton_Click(object sender, EventArgs e)
{
Properties.Settings.Default.userBoolSetting = checkBox1.Checked;
}

private void setUserStringDefaultButton_Click(object sender, EventArgs e)
{
Properties.Settings.Default.userStringSetting = userStringTextBox.Text;
}

private void setUserIntDefaultButton_Click(object sender, EventArgs e)
{
Properties.Settings.Default.userIntSetting = (int) userIntNumPicker.Value;
}

private void setComboBoxDefaultButton_Click(object sender, EventArgs e)
{
// This setting was added at runtime, so its is not a Property the in Settings wrapper.
// Must use the wrapper Properties
Properties.Settings.Default.Properties["comboBoxDefaultSetting"].DefaultValue = comboBox1.Text;
}

private void newToolStripButton_Click(object sender, EventArgs e)
{
MessageBox.Show("The New button was clicked.", this.Text);
}

private void openToolStripButton_Click(object sender, EventArgs e)
{
MessageBox.Show("The Open button was clicked.", this.Text);
}

private void saveToolStripButton_Click(object sender, EventArgs e)
{
MessageBox.Show("The Save button was clicked.", this.Text);
}
}
qcrsoft 2006-11-30
  • 打赏
  • 举报
回复
“请参考微软101sample winform里面关于ClientConfiguration的那一段”
在哪?指点下迷津
heiyefeng 2006-11-30
  • 打赏
  • 举报
回复
记录到配置文件中比较好,我个人除非很有必要,一般不写信息到注册表
commonmj 2006-11-30
  • 打赏
  • 举报
回复
那就好办了, 请参考微软101sample winform里面关于ClientConfiguration的那一段.
zerg318 2006-11-30
  • 打赏
  • 举报
回复
不知道能不能 像自动保存登录用户名那样处理 ,把用户设置的值保存起来(保存到数据库或者在属性设置里面),每次打开读取那个值就是
没试过 个人想法
qcrsoft 2006-11-30
  • 打赏
  • 举报
回复
有啊,主题铁里我写了,我是想知道有没有更好的方式
commonmj 2006-11-30
  • 打赏
  • 举报
回复
记不难(setting.setting or app.config), 楼主有办法设置每列为固定宽度吗
qcrsoft 2006-11-30
  • 打赏
  • 举报
回复
你在资源管理器里从来没调整过列宽吗?
zhangfire 2006-11-30
  • 打赏
  • 举报
回复
不会,嘿嘿。
实用吗?你只需要想办法让每列都能在一个适当的宽度显示,这才是正道。
qcrsoft 2006-11-29
  • 打赏
  • 举报
回复
不会吧,这样功能很使用啊,windows资源管理器什么的不都会记下你的列宽么~~
zhangfire 2006-11-29
  • 打赏
  • 举报
回复
建议还是在程序中设置一个合适的值吧,你这还真是给自己找罪受,要不就是不懂技术的老板要求的。

110,536

社区成员

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

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

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