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
  1. Home
  2. General Programming
  3. C#
  4. Sorting on Datagridview removes values from Image column en removes row.height [modified]

Sorting on Datagridview removes values from Image column en removes row.height [modified]

Scheduled Pinned Locked Moved C#
algorithmsdata-structuresxmlhelp
2 Posts 1 Posters 0 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.
  • D Offline
    D Offline
    ddecoy
    wrote on last edited by
    #1

    Hi all, Wel the title says it all... I have a datagridview with a dataset as Datasource, having a few textcolumns and an imagecolumn. When I click on the columnheader of a textcolumn the sorting happens but all my rows are back at the initial height and all the images are gone from the imagecolumn... strange behaviour,

    public partial class Form1 : Form
    {
    private DataSet Dataset1;
    private FileDialog FileDialog1;
    private StringCollection rows ;

        public Form1()
        {
            InitializeComponent();
    
            Dataset1 = new DataSet();
            Dataset1.ReadXml(@"..\\..\\Current.xml");
            dataGridView1.DataSource = Dataset1;
            dataGridView1.DataMember = "item";
    
    
            this.FormClosing += new FormClosingEventHandler(FormClosing1);
            this.Activated += new EventHandler(FrmActive);
    
            FileDialog1 = new OpenFileDialog();
    
    
    
            // Restore the columns' state
            StringCollection cols = new StringCollection();
            cols = Properties.Settings.Default.DataGridViewFormColumns;
            for (int i = 0; i < cols.Count; ++i)
            {
                string\[\] array = cols\[i\].Split(',');
                this.dataGridView1.Columns\[i\].DisplayIndex = Int16.Parse(array\[0\]);
                this.dataGridView1.Columns\[i\].Width = Int16.Parse(array\[1\]);
                this.dataGridView1.Columns\[i\].Visible = bool.Parse(array\[2\]);
            }
    
          }
    
        private void FrmActive(object sender, EventArgs e)
        {
            SetPics();
    
            // I do this only once when the form starts ... so remove handler //
            this.Activated -= new EventHandler(FrmActive);
            this.dataGridView1.Rows\[0\].Height = 100;
    
            // get settings
            rows = new StringCollection();
            rows = Properties.Settings.Default.DataGridViewFormRows;
            for (int i = 0; i < rows.Count; ++i)
            {
                this.dataGridView1.Rows\[i\].Height = Convert.ToInt16(rows\[i\]);
            }
        }
    
    
       // here i want to keep the column and rows height , here is NO problem
        private void FormClosing1(object sender, EventArgs e)
        {
            Dataset1.WriteXml(@"..\\..\\Current.xml");
            StringCollection stringCollection = new StringCollection();
            foreach (DataGridViewColumn column in this.dataGridView1.Columns)
                {
                stringColl
    
    D 1 Reply Last reply
    0
    • D ddecoy

      Hi all, Wel the title says it all... I have a datagridview with a dataset as Datasource, having a few textcolumns and an imagecolumn. When I click on the columnheader of a textcolumn the sorting happens but all my rows are back at the initial height and all the images are gone from the imagecolumn... strange behaviour,

      public partial class Form1 : Form
      {
      private DataSet Dataset1;
      private FileDialog FileDialog1;
      private StringCollection rows ;

          public Form1()
          {
              InitializeComponent();
      
              Dataset1 = new DataSet();
              Dataset1.ReadXml(@"..\\..\\Current.xml");
              dataGridView1.DataSource = Dataset1;
              dataGridView1.DataMember = "item";
      
      
              this.FormClosing += new FormClosingEventHandler(FormClosing1);
              this.Activated += new EventHandler(FrmActive);
      
              FileDialog1 = new OpenFileDialog();
      
      
      
              // Restore the columns' state
              StringCollection cols = new StringCollection();
              cols = Properties.Settings.Default.DataGridViewFormColumns;
              for (int i = 0; i < cols.Count; ++i)
              {
                  string\[\] array = cols\[i\].Split(',');
                  this.dataGridView1.Columns\[i\].DisplayIndex = Int16.Parse(array\[0\]);
                  this.dataGridView1.Columns\[i\].Width = Int16.Parse(array\[1\]);
                  this.dataGridView1.Columns\[i\].Visible = bool.Parse(array\[2\]);
              }
      
            }
      
          private void FrmActive(object sender, EventArgs e)
          {
              SetPics();
      
              // I do this only once when the form starts ... so remove handler //
              this.Activated -= new EventHandler(FrmActive);
              this.dataGridView1.Rows\[0\].Height = 100;
      
              // get settings
              rows = new StringCollection();
              rows = Properties.Settings.Default.DataGridViewFormRows;
              for (int i = 0; i < rows.Count; ++i)
              {
                  this.dataGridView1.Rows\[i\].Height = Convert.ToInt16(rows\[i\]);
              }
          }
      
      
         // here i want to keep the column and rows height , here is NO problem
          private void FormClosing1(object sender, EventArgs e)
          {
              Dataset1.WriteXml(@"..\\..\\Current.xml");
              StringCollection stringCollection = new StringCollection();
              foreach (DataGridViewColumn column in this.dataGridView1.Columns)
                  {
                  stringColl
      
      D Offline
      D Offline
      ddecoy
      wrote on last edited by
      #2

      workround: If I sort from code I have a work round to add the images again after DatagridView.Sort() but if a user sorts by clicking then I need a event like 'AfterSort' or something which doesn't seem to exist ... ...

      °°°°°°°°°°°°°°°°°°°°°°° -- Inter Access Belgium --

      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