能否通过datagrid显示的列数来决定显示数据?(这想法是不是太难了?)

lcge 2004-08-31 07:51:28
Private Sub DataGrid1ClickChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
datagirdsub()
End Sub

Private Sub datagirdsub()
If DataGrid1.CurrentRowIndex <= xx - 1 And DataGrid1.CurrentRowIndex >= 0 Then
Me.Label12.Text = Me.DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 1)
Me.TextBox4.Text = Me.DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 3)
Me.ComboBox3.Text = Me.DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 0)
Me.ComboBox4.Text = Me.DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 2)
Me.Label34.Text = Me.DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 4)
end if

以上会出现这种情况:
datagrid1显示的列数不管是不是4列,只要你点击datagrid1,它们都显示出来.能否使datagrid1只显示4列时,点击datagrid1才显示!
...全文
74 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
thinkingforever 2004-09-01
  • 打赏
  • 举报
回复
还有首先实例化他们
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn1 = new System.Windows.Forms.DataGridTextBoxColumn();
thinkingforever 2004-09-01
  • 打赏
  • 举报
回复
//
// dataGrid1
//
this.dataGrid1.DataMember = "表名";
this.dataGrid1.DataSource = this.dataset11;
this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 210);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(720, 296);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] { this.dataGridTableStyle1});
//
// dataGridTableStyle1
//
this.dataGridTableStyle1.DataGrid = this.dataGrid1;
this.dataGridTableStyle1.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] { this.dataGridTextBoxColumn1,
});
this.dataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGridTableStyle1.MappingName = "表名";

//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Format = "";
this.dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.HeaderText = "ID";
this.dataGridTextBoxColumn1.MappingName = "列名";
this.dataGridTextBoxColumn1.Width = 75;
lcge 2004-09-01
  • 打赏
  • 举报
回复

怎样判断一下datagrid的列数?(正是我要解决的.)
KahnWinsock 2004-09-01
  • 打赏
  • 举报
回复
致作者:
首先,你为什么不使用datagrid的click事件?
其次,你为什么不在DataGrid1ClickChanged事件里调用函数的时候加上判断条件?datagirdsub()只是负责显示,而用不用显示应该 你来控件,所以,在DataGrid1ClickChanged里面加一个if语句,先判断一下datagrid的列数,然后再决定是否显示。
lcge 2004-08-31
  • 打赏
  • 举报
回复
能否给个代码,本人刚学的.
thinkingforever 2004-08-31
  • 打赏
  • 举报
回复
在代码中给DataGrid添加DataGridTableStyle,在DataGridTableStyle添加datacloumn,
在给每一列帮定数据.
木头呆但不傻 2004-08-31
  • 打赏
  • 举报
回复
用DataGridTableStyle试试

16,552

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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