Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Datagridview Databinding Problem?

Datagridview Databinding Problem?

Scheduled Pinned Locked Moved C#
databasewpfwcfhelpquestion
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pawan Kiran
    wrote on last edited by
    #1

    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();

    T 1 Reply Last reply
    0
    • P Pawan Kiran

      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();

      T Offline
      T Offline
      T M Gray
      wrote on last edited by
      #2

      I am surprised there are any rows in the grid at all. You never call DataBind(). When you step through the code int he debugger with a watch on dtable.Rows.Count and a breakpoint at dgrid.DataSource = dtable; are you sure it says 12? Or are you just assuming there should be 12 records when it gets to that point?

      P 1 Reply Last reply
      0
      • T T M Gray

        I am surprised there are any rows in the grid at all. You never call DataBind(). When you step through the code int he debugger with a watch on dtable.Rows.Count and a breakpoint at dgrid.DataSource = dtable; are you sure it says 12? Or are you just assuming there should be 12 records when it gets to that point?

        P Offline
        P Offline
        Pawan Kiran
        wrote on last edited by
        #3

        hi before posting this question only i checked all the above things which u said. it is showing perfect 12 records dtable.rows.count in immediate window when i am binding the same to Datagridview also, the dgrid.rows.count is 12 only.. but it is not showing the 12 records in grid, instead of 12 it displays only 1 record.. Let me know if u have any solution.. Thanks and Regards, Pawan.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups