Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All

I have a datagridview (whose columns can be filtered) .
For the first time the gridview is loaded datatable is storing only those values.
If i change the dropdown to display another values its not updating.
Please can someone help me.

C#
protected override void OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e)
      {

          if (dataSource == null)
              dataSource = (DataTable)this.DataSource;

          positionX = e.X;
          positionY = e.Y;

          bool flag = false;
          for (int columnCount = 0; columnCount < dataSource.Columns.Count; columnCount++)
          {
              if (!flag)
              {
                  positionX = positionX + this.Columns[columnCount].Width;
                  if (this.Columns[columnCount].Name == this.Columns[e.ColumnIndex].Name)
                      flag = true;
              }
          }
          positionX = positionX - this.Columns[0].Width;

          if (e.Button == MouseButtons.Right)
          {

              ContextMenu filterContextMenu = new ContextMenu();
              if (filterColumnList.Contains(this.Columns[e.ColumnIndex].HeaderText))
              {
                  columnName = this.Columns[e.ColumnIndex].HeaderText;

                  ArrayList columnFilterList = new ArrayList();
                  for (int count = 0; count < dataSource.Rows.Count; count++)
                  {

                      try
                      {
                          if (!columnFilterList.Contains(dataSource.Rows[count][columnName].ToString()))
                              columnFilterList.Add(dataSource.Rows[count][columnName].ToString());
                      }
                      catch
                      {


                      }
                  }
                  columnFilterList.Sort();





                  for (int count = 0; count < columnFilterList.Count; count++)
                  {
                      MenuItem uniqueColumnsMenuItem = new MenuItem();
                      uniqueColumnsMenuItem.Name = columnFilterList[count].ToString();
                      uniqueColumnsMenuItem.Text = columnFilterList[count].ToString();

                      if (checkedFilterHashTable.Contains(columnName))
                      {
                          if (((ArrayList)checkedFilterHashTable[columnName]).Contains(uniqueColumnsMenuItem.Text))
                              uniqueColumnsMenuItem.Checked = true;
                          else
                              uniqueColumnsMenuItem.Checked = false;
                      }

                      uniqueColumnsMenuItem.Click += new EventHandler(menuItem_Click);
                      filterContextMenu.MenuItems.Add(uniqueColumnsMenuItem);
                  }

                  filterContextMenu.MenuItems.Add("-");
                  MenuItem clearThisFilterMenuItem = new MenuItem();
                  clearThisFilterMenuItem.Name = "Clear This Filter";
                  clearThisFilterMenuItem.Text = "Clear This Filter";
                  filterContextMenu.MenuItems.Add(clearThisFilterMenuItem);
                  filterContextMenu.MenuItems.Add("-");

                  MenuItem clearAllFilterMenuItem = new MenuItem();
                  clearAllFilterMenuItem.Name = "Clear All Filters";
                  clearAllFilterMenuItem.Text = "Clear All Filters";
                  filterContextMenu.MenuItems.Add(clearAllFilterMenuItem);

                  clearThisFilterMenuItem.Click += new EventHandler(menuItem_Click);
                  clearAllFilterMenuItem.Click += new EventHandler(menuItem_Click);

              }

              filterContextMenu.Show(this, new Point(positionX, e.Y));
          }
      }


Thanks
Posted
Updated 11-Sep-14 3:54am
v2
Comments
Thanks7872 11-Sep-14 9:50am    
Then update the source of the datagridview with the related data. Whats the issue? Where is the code you have implemented till now.

Use Improve question at bottom of the question and post relevant code block also.
j snooze 11-Sep-14 17:56pm    
If I comprehend your question correctly, try enabling postback on your drop down.
Thomas Nielsen - getCore 12-Sep-14 4:06am    
Appears to be missing central components in play. Like what kind of DataGrid? What data is loading? What are you binding to what and where. I'm not sure it is correct to assume that the problem is in your filter context menu click method.
Must post more code or reproduce the problem in a simpler solution that you can post from to get help here. right now it's a bit like a problem description 'i get wet, please help me' but we have to know if you're in the rain, somebody's pointing a firehose at your or you're standing in a pool :)

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