Click here to Skip to main content
16,010,022 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 28-May-10 1:58am
v2

1 solution

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?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900