Datagridview数据绑定问题? [英] Datagridview Data binding problem?

查看:79
本文介绍了Datagridview数据绑定问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我将数据表绑定到datagridview时,它没有显示出datagridview中的所有记录..

它在datagridview中仅显示1条记录..
数据表中的实际记录为12.

有什么主意,让我知道..

这是我的代码


公共静态DataTable dtable = new DataTable();
私有无效ScheduledJobs_Load(对象发送者,EventArgs e)
{
试试
{
FillGrid();
如果(dtable.Rows.Count& gt; 0)
{
dgrid.DataSource = dtable;
}
}
赶上{}
}
私有void FillGrid()
{
试试
{
如果(dtable.Rows.Count == 0)
{
ProcessStartInfo ps = new ProcessStartInfo("SCHTASKS","/QUERY/fo table");
ps.RedirectStandardOutput = true;
ps.UseShellExecute = false;
进程p = Process.Start(ps);
p.OutputDataReceived + =新的DataReceivedEventHandler(p_OutputDataReceived);
p.BeginOutputReadLine();
}
}
赶上{}
}
System.Collections.ArrayList ar =新的System.Collections.ArrayList();
int first = 0;
void p_OutputDataReceived(对象发送者,DataReceivedEventArgs e)
{
试试
{
if(first == 0& amp; amp; dtable.Columns.Count == 0)
{
dtable.Columns.Add(任务名称");
dtable.Columns.Add("Next RunTime");
dtable.Columns.Add("Status");
}
ar.Add(e.Data);
if(first& gt; 2& amp; amp; ar [first]!= null)
{
DataRow dr = dtable.NewRow();
dr [0] = ar [first] .ToString().Substring(0,ar [first] .ToString().IndexOf('':'')-2).Trim();
dr [1] = ar [first] .ToString().Substring(ar [first] .ToString().IndexOf('':'')-2,20).Trim();
dr [2] = ar [first] .ToString().Substring(ar [first] .ToString().IndexOf('':'')+ 18).Trim();
dtable.Rows.Add(dr);
}
first ++;
}
赶上{}
}


提前谢谢.

Pawan.

Hi,

when i am binding datatable to datagridview, it is not showing all the records in the datagridview..

it is displaying only 1 Record in datagridview..
actual records in datatable are 12.

have any idea,let me know..

here is my code


public static DataTable dtable = new DataTable();
private void ScheduledJobs_Load(object sender, EventArgs e)
{
try
{
FillGrid();
if (dtable.Rows.Count > 0)
{
dgrid.DataSource = dtable;
}
}
catch { }
}
private void FillGrid()
{
try
{
if (dtable.Rows.Count == 0)
{
ProcessStartInfo ps = new ProcessStartInfo("SCHTASKS", "/QUERY /fo table");
ps.RedirectStandardOutput = true;
ps.UseShellExecute = false;
Process p = Process.Start(ps);
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
p.BeginOutputReadLine();
}
}
catch { }
}
System.Collections.ArrayList ar = new System.Collections.ArrayList();
int first = 0;
void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
try
{
if (first == 0 && dtable.Columns.Count == 0)
{
dtable.Columns.Add("Task Name");
dtable.Columns.Add("Next RunTime");
dtable.Columns.Add("Status");
}
ar.Add(e.Data);
if (first > 2 && ar[first] != null)
{
DataRow dr = dtable.NewRow();
dr[0] = ar[first].ToString().Substring(0, ar[first].ToString().IndexOf('':'') - 2).Trim();
dr[1] = ar[first].ToString().Substring(ar[first].ToString().IndexOf('':'') - 2, 20).Trim();
dr[2] = ar[first].ToString().Substring(ar[first].ToString().IndexOf('':'') + 18).Trim();
dtable.Rows.Add(dr);
}
first++;
}
catch { }
}


Thanks in advance.

Pawan.

推荐答案

使用您提供的信息,几乎不可能诊断出问题.

您是在设计器中还是在代码中进行数据绑定?

如果使用代码,则如果您编辑问题以显示用于执行此操作的代码,将很有帮助.

如果在Designer中,您是否接受向导提供的默认设置,或者正在修改其中的任何默认设置?
With the information that you have provided, it is almost impossible to diagnose the problem.

Are you doing the DataBinding in the Designer or in code?

If in code it would help if you edited your question to show the code you are using to do so.

If in the Designer, are you accepting the defaults offered by the Wizard(s) or are you modifying any of them?


这篇关于Datagridview数据绑定问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆