Datagrid problem...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anthony Boudouvas

    #1

    Datagrid problem...

    Hi to all,

    i think, this datagrid will drive me nuts...
    I have the below code and i cannot figure out what is wrong and i cannot
    format
    the columns in the grid.
    I, for example, try to format some things in "Sender" column but this is not
    happening..


    Can anyone give me a shot before i jump out of the window ??

    thanks a lot for any help!


    anthonyb




    SqlConnection cnn = ...
    cnn.Open();
    SqlCommand cmd = new SqlCommand("Ema ils_FetchPendin g", cnn);
    cmd.CommandType = CommandType.Sto redProcedure;

    SqlDataAdapter da = new SqlDataAdapter( cmd);
    AddGridStyle();

    DataSet ds = new DataSet();
    da.Fill(ds, "MyTable");
    gridPendings.Da taSource = ds;
    gridPendings.Da taMember = "MyTable";
    cnn.Close();

    private void AddGridStyle()
    {
    DataGridTableSt yle ts = new DataGridTableSt yle();
    ts.MappingName = "MyTable";
    DataGridTextBox Column sender = new DataGridTextBox Column();
    sender.MappingN ame = "Sender";
    sender.HeaderTe xt = "anthonyb";
    ts.GridColumnSt yles.Add(sender );
    grid.TableStyle s.Add(ts);
    }


  • Morten Wennevik

    #2
    Re: Datagrid problem...

    Datagrids aren't what I know most about, but shouldn't you have a
    gridPendings.Da taBind();
    to fill the datagrid with the dataset data?
    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

    Comment

    • Anthony Boudouvas

      #3
      Re: Datagrid problem...


      "Morten Wennevik" <mortenwennevik @hotmail.com> wrote in message
      news:oprvk82j0b ge0n9a@localhos t...[color=blue]
      > Datagrids aren't what I know most about, but shouldn't you have a
      > gridPendings.Da taBind();
      > to fill the datagrid with the dataset data?
      > --
      > Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/[/color]


      But i use :
      DataSet ds = new DataSet();
      da.Fill(ds, "MyTable");

      What is wrong with that ?


      Comment

      • Morten Wennevik

        #4
        Re: Datagrid problem...

        That fills the dataset, but it doesn't fill the datagrid. You only tell
        the datagrid that the datasource is ds, but you need to call DataBind() to
        transfer data to the grid. I think.

        --
        Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

        Comment

        • Eric Cadwell

          #5
          Re: Datagrid problem...

          Works for me. Only noticed one error in the AddGridStyle function:

          When loading the DataAdapter and setting the DataSource you reference
          gridPendings...

          gridPendings.Da taSource = ds;
          gridPendings.Da taMember = "MyTable";

          But in the AddGridStyle function, you reference a different grid...

          grid.TableStyle s.Add(ts);


          If that's not the issue try playing with the TableStyle.Mapp ingName. I've
          had issues with this, but can't document it as a bug. I now use the same
          string for all my table names. It seems resistant to change!

          HTH,
          Eric Cadwell



          "Anthony Boudouvas" <anthonyb@media tel.gr> wrote in message
          news:O3iRIUFfDH A.3788@tk2msftn gp13.phx.gbl...[color=blue]
          > The grid displays correctly the data, but in an incorrect way...
          > Thanks anyway!
          >
          >
          >
          > "Morten Wennevik" <mortenwennevik @hotmail.com> wrote in message
          > news:oprvk9s4qc ge0n9a@localhos t...[color=green]
          > > That fills the dataset, but it doesn't fill the datagrid. You only tell
          > > the datagrid that the datasource is ds, but you need to call DataBind()[/color][/color]
          to[color=blue][color=green]
          > > transfer data to the grid. I think.
          > >
          > > --
          > > Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/[/color]
          >
          >[/color]


          Comment

          • ivst

            #6
            Re: Datagrid problem...

            Anthony, how exactly do you do formatting?

            this works fine for me (just make sure sender.MappingN ame == column name in the "MyTable" table):
            sender.Format = "c"; //or "$0.000" and so on...


            "Anthony Boudouvas" <anthonyb@media tel.gr> wrote in message news:OmTMF0DfDH A.3248@tk2msftn gp13.phx.gbl...[color=blue]
            > Hi to all,
            >
            > i think, this datagrid will drive me nuts...
            > I have the below code and i cannot figure out what is wrong and i cannot
            > format
            > the columns in the grid.
            > I, for example, try to format some things in "Sender" column but this is not
            > happening..
            >
            >
            > Can anyone give me a shot before i jump out of the window ??
            >
            > thanks a lot for any help!
            >
            >
            > anthonyb
            >
            >
            >
            >
            > SqlConnection cnn = ...
            > cnn.Open();
            > SqlCommand cmd = new SqlCommand("Ema ils_FetchPendin g", cnn);
            > cmd.CommandType = CommandType.Sto redProcedure;
            >
            > SqlDataAdapter da = new SqlDataAdapter( cmd);
            > AddGridStyle();
            >
            > DataSet ds = new DataSet();
            > da.Fill(ds, "MyTable");
            > gridPendings.Da taSource = ds;
            > gridPendings.Da taMember = "MyTable";
            > cnn.Close();
            >
            > private void AddGridStyle()
            > {
            > DataGridTableSt yle ts = new DataGridTableSt yle();
            > ts.MappingName = "MyTable";
            > DataGridTextBox Column sender = new DataGridTextBox Column();
            > sender.MappingN ame = "Sender";
            > sender.HeaderTe xt = "anthonyb";
            > ts.GridColumnSt yles.Add(sender );
            > grid.TableStyle s.Add(ts);
            > }
            >
            >[/color]


            Comment

            • Anthony Boudouvas

              #7
              Re: Datagrid problem...

              Eric you were right, that was indeed a problem with the code,
              i wasn't referring to the correct grid.
              But the problem really gon away when i used something like this:


              ts.GridColumnSt yles.Add(SetCol umnStyle("Email ID", "EmailID",
              LongestField((D ataSet) gridSent.DataSo urce, "MyTable", gridSent,
              "EmailID")) );

              gridSent.TableS tyles.Add(ts);


              And imagine doing this for every column in the grid...
              I have worked in the past with third-party grids for vb6 and it was very
              easy.
              I see that in the datagrid you have even moe control on it,
              but an "Autosize" property would make more sense...

              thanks again!


              Comment

              • Eric Cadwell

                #8
                Re: Datagrid problem...

                Yes, I think syncfusion has a good autosize table routine.

                http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp

                Tip 5.48. Download the demo and he has a function that loops the columns and
                autosizes them all. Not sure if he handled hidden columns but that's an easy
                fix.

                Alternatively if you want the columns to fit the width of the grid, just
                divide the (width of the grid minus the row header width) by the number of
                visible columns (to hide a column set width to 0)

                HTH,
                Eric Cadwell



                "Anthony Boudouvas" <anthonyb@media tel.gr> wrote in message
                news:OIOinuPfDH A.2400@TK2MSFTN GP11.phx.gbl...[color=blue]
                > Eric you were right, that was indeed a problem with the code,
                > i wasn't referring to the correct grid.
                > But the problem really gon away when i used something like this:
                >
                >
                > ts.GridColumnSt yles.Add(SetCol umnStyle("Email ID", "EmailID",
                > LongestField((D ataSet) gridSent.DataSo urce, "MyTable", gridSent,
                > "EmailID")) );
                >
                > gridSent.TableS tyles.Add(ts);
                >
                >
                > And imagine doing this for every column in the grid...
                > I have worked in the past with third-party grids for vb6 and it was very
                > easy.
                > I see that in the datagrid you have even moe control on it,
                > but an "Autosize" property would make more sense...
                >
                > thanks again!
                >
                >[/color]


                Comment

                Working...