我有2个表格。 MainPage表单包含datagridview和fetchTradeReport方法来填充/刷新datagrid,而ColumnSettings表单用于配置用户想要显示的datagridviewcolumn。我有"申请变更" ColumnSettings表单中的按钮,我在click事件中包含fetchTradeReport方法。但是,数据网格仍然相同,并且在我点击它之后不会改变。
这是我的fetchTradeReport方法
public void fetchTradeReport()
{
try
{
TTransport transport = new TSocket(address, port);
TProtocol protocol = new TBinaryProtocol(transport);
CacheService.Client client = new CacheService.Client(protocol);
transport.Open();
List<string> transactTime = new List<string>();
SearchCriteria criteria = new SearchCriteria();
criteria.Filters = new List<Filter>();
DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
if (Convert.ToString(tradeStatusCB.Text) != "")
setTradeStatusFilter(criteria, (TradeReportStatus)Enum.Parse(typeof(TradeReportStatus), Convert.ToString(tradeStatusCB.Text)));
if (platformTB.Text != "")
setPlatformFilter(criteria, platformTB.Text);
if (exchangeTB.Text != "")
criteria.Exchange = exchangeTB.Text;
if (productTB.Text != "")
criteria.Product = productTB.Text;
if (accountTB.Text != "")
criteria.Account = accountTB.Text;
if (orderidTB.Text != "")
setOrderIDFilter(criteria, orderidTB.Text);
if (tradereportidTB.Text != "")
setReportIDFilter(criteria, tradereportidTB.Text);
if (tradedateDTP.Text.Length != 1)
criteria.TradeDate = Convert.ToInt32(tradedateDTP.Value.ToString("yyyyMMdd"));
var tradeList = client.getTradeReports(criteria);
tradeGridView.DataSource = tradeList;
foreach (DataGridViewRow row in tradeGridView.Rows)
{
double time = Convert.ToDouble(row.Cells["TransactTime"].Value);
string dtm = dt.AddSeconds(time).ToLocalTime().ToString();
transactTime.Add(dtm);
}
tradeGridView.Columns.Remove("TransactTime");
if(tradeGridView.Columns.Contains("TransactionTime"))
tradeGridView.Columns.Remove("TransactionTime");
tradeGridView.Columns.Add("TransactionTime", "TransactionTime");
tradeGridView.Columns["TransactionTime"].ValueType = typeof(String);
int i = 0;
foreach (DataGridViewRow row in tradeGridView.Rows)
{
row.Cells["TransactionTime"].Value = transactTime[i];
i++;
}
int counter = 0;
string line;
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\\ColumnSettings.config"))
{
StreamReader readFile = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\\ColumnSettings.config");
while ((line = readFile.ReadLine()) != null)
{
string columnName = line.Substring(0, line.Length - 2);
tradeGridView.Columns[columnName].DisplayIndex = counter;
if (line.Split('-').Last() == "1")
tradeGridView.Columns[columnName].Visible = true;
else
tradeGridView.Columns[columnName].Visible = false;
counter++;
}
readFile.Close();
}
else
collectColumnName();
transport.Close();
}
catch (Exception e)
{
MessageBox.Show(e.StackTrace);
}
}
这就是我在&#34; Apply Changes&#34; ColumnSettings表单中的按钮单击事件
new MainPage(GetConnectionString.address, GetConnectionString.port).fetchTradeReport();
对不起,如果我的英语不好。任何帮助赞赏。感谢。