按标题文本匹配格式对datagridveiw中的列进行排序 [英] Sort columns in datagridveiw by headertext match format

查看:83
本文介绍了按标题文本匹配格式对datagridveiw中的列进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Developers,
我是Vishal Sharma
我使用数据集将csv文件加载到datagridview中.
我按headertext
分别对三列和三列进行排序
我的代码是:

Hi Developers,
I am Vishal Sharma
I load a csv file into datagridview using dataset.
I sort a three each columns and rows by headertext

my code is:

public static DataSet GetDataset(string filename)
{
  string Connectionstring = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Text;",
            Path.GetDirectoryName(filename));
  string cmdstring1 = string.Format(@"select * FROM {0} order by ID_NUM desc,START_DATE asc,END_DATE asc", Path.GetFileName(filename));
            DataSet dataset = new DataSet();
          
  using (OleDbConnection olconn = new OleDbConnection(Connectionstring))
  {
    olconn.Open();
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    adapter.SelectCommand = new OleDbCommand(cmdstring, olconn);
    adapter.Fill(dataset, "Test");
    olconn.Close();               
  }
  return dataset;
}

public void Loaded_Click(object sender, EventArgs e)
{          
  DataSet dataset = Form1.GetDataset(Locations.Text);
  DGV.DataSource = dataset.Tables[0].DefaultView;
}



问题是如果这样写START_DATE开始日期
如果END_DATE的写法是这样的结束日期
确实发生了
无效的字符串
和文件无法加载.
因此,请告诉我,如果在csv文件加载时以匹配的任何顺序返回开始日期和结束日期的字母,则在代码中应用哪种条件.
请接受我的要求并解决这种情况.谢谢.



The problem is that if START_DATE is write like this start date
and if END_DATE is write like this end date
exception does occur
invalid string
and file cannot be loaded.
So, tell me which condition is applied in the code if alphabet of start date and the end date are return in any order they are match at load time of csv file.
Please accept my request and solve this situation. Thank you.

推荐答案

放在方括号中

即结束日期必须为[结束日期]或结束日期"

我还建议您执行排序输入代码,因此您可以使用表Default View,然后根据需要提供更多自定义排序选项.删除语句末尾的排序,然后执行以下操作:

put it in brackets

i.e. end date would have to be [end date] or ''end date''

I would also suggest doing the sorting IN code, so your using the table Default View and then you can give some more custom sorting options if needed. Remove the sort at the end of your statement and do this:

DataTable objtb = new DataTable();
// Do stuff to fill objtb here
DataView dv = objtb.DefaultView;
dv.Sort = "[start date] asc, [end date] asc";
DGV.DataSource = dv;


这篇关于按标题文本匹配格式对datagridveiw中的列进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆