Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Change of Columntypes after Rowfilter Bug.
 

Change of Columntypes after Rowfilter Bug.

I have following issue, i have a datagrid which consists of:

Textfield
Textfield
ComboBox
ComboBox
CheckBox

I do load it initially with a XML, every works fine.

But as soon as i apply a rowfilter the columntypes are being modified in text fields, what i am i doing wrong?

This is the Code:

Code Snippet

using System;
using System.Data;
using System.Windows.Forms;
using System.Xml;

namespace AllianceAdmin
{

public partial class Form1 : Form
{
DataSet ds = new DataSet("NationsDS");
public Form1()
{
InitializeComponent();
Load_Xml();

}
private void Load_Xml()
{
XmlDataDocument xmlDatadoc = new XmlDataDocument();
xmlDatadoc.DataSet.ReadXml("nations.xml");
ds = xmlDatadoc.DataSet;
NationsGrid.DataSource = ds.DefaultViewManager;
NationsGrid.DataMember = "Nation";
}


private void Save_Click(object sender, EventArgs e)
{
DataViewManager dsgrid = (DataViewManager)NationsGrid.DataSource;
dsgrid.DataSet.WriteXml("nations.xml", XmlWriteMode.IgnoreSchema);

}
private void button1_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItems.Count == 0)
{
MessageBox.Show("Select at least 1 resource");
}
if (listBox1.SelectedItems.Count > 2)
{
MessageBox.Show("Select 1 or 2 resources");
}

if (listBox1.SelectedItems.Count == 1)
{
ds.Tables[0].DefaultView.RowFilter = "resource1 like '" + listBox1.SelectedItems[0] + "' or resource2 like '" + listBox1.SelectedItems[0] + "'";
Save.Enabled = false;

NationsGrid.DataSource = ds.Tables[0];

}
if (listBox1.SelectedItems.Count == 2)
{
ds.Tables[0].DefaultView.RowFilter = "(resource1 like '" + listBox1.SelectedItems[0] + "' and resource2 like '" + listBox1.SelectedItems[1] + "') or (resource1 like '" + listBox1.SelectedItems[1] + "' and resource2 like '" + listBox1.SelectedItems[0] + "')";
Save.Enabled = false;

NationsGrid.DataSource = ds.Tables[0];
}
}

private void Reset_Click(object sender, EventArgs e)
{
Load_Xml();
Save.Enabled = true;
NationsGrid.ReadOnly = false;
}
}
}


Raptorix  Tuesday, July 15, 2008 10:37 AM

Hi Raptorix,

According to my understanding about your post, you problem is that when you filter the data the DataGridViewComboBoxColumn changed to DataGridViewTextBoxColumn, right? I looked through your code and found that you reset the DataSource for the DataGridView when you filter the data. This may be the reason why the DataGridViewComboBoxColumn changed to DataGridViewTextBoxColumn. You can try to set the AutoGenerateColumns property to false in the designer to see if you still have the problem.

Let me know if this helps, if not, could you please provide more detailed information?

Best regards.
Rong-Chun Zhang

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Rong-Chun Zhang  Friday, July 18, 2008 1:30 PM

Hi Raptorix,

According to my understanding about your post, you problem is that when you filter the data the DataGridViewComboBoxColumn changed to DataGridViewTextBoxColumn, right? I looked through your code and found that you reset the DataSource for the DataGridView when you filter the data. This may be the reason why the DataGridViewComboBoxColumn changed to DataGridViewTextBoxColumn. You can try to set the AutoGenerateColumns property to false in the designer to see if you still have the problem.

Let me know if this helps, if not, could you please provide more detailed information?

Best regards.
Rong-Chun Zhang

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Rong-Chun Zhang  Friday, July 18, 2008 1:30 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridViewColumnHeaderCell
• Can't get DataGridView column alignment to work
• Binding an Array of objects to a DataGridView
• Updating Values in a datatable
• Limits on the number of tables or fields in a datasource?
• BindingSource.DataSource = <Interface>
• Remove rows in datagridview and save the dataset xml file
• DataGrid Control in vb2003
• CellType Problem
• DataGridView inserting records