我已经从配置文件中将设置名称及其各自的值提取到有序字典中.字典包含ICollection类的键和值.我想绑定该数据并将其显示在DataGridView中.我已经尝试将字符串复制到数组并显示这些数组,但是当我运行程序时,列是空白的,它似乎根本没有绑定.
我还尝试将DataGridView源直接设置为有序字典集合(键或值),但这也没有产生我想要的任何东西; 列仍然是空白的.但是,第三列的列名称为"length",并显示ICollection中条目的长度.但不用说我不想要长度,我想要条目本身.
这是我用于此问题的代码:在加载表单时,我加载配置文件,名为m_Settings的私有成员具有所有键值对.然后我创建一个列表并分别添加键和值.将绑定源设置为'data'后,我运行程序,我添加的两个列都是空白的.
private void Form4_Load(object sender, EventArgs e)
{
loadconfigfile(Properties.Settings.Default.Config);
List<Object> data = new List<Object>();
data.Add(m_Settings.Keys);
data.Add(m_Settings.Values);
bindingSource1.DataSource = data;
dataGridView1.DataSource = bindingSource1;
dataGridView1.Refresh();
}
Run Code Online (Sandbox Code Playgroud)
关于如何获得有序字典并在标有"设置"和"值"的两列中显示条目的任何想法?我相信列表是兼容DataGridViews的DataSources,但现在我开始猜测自己了.
任何帮助或方向非常感谢!如果需要,我很乐意提供更多信息.
谢谢!
编辑:
以下是已实现的myStruct类的修订代码:
List<myStruct> list = new List<myStruct>();
for(int index = 0; index < m_Settings.Count; index++)
{
myStruct pair = new myStruct(keys[index], values[index].ToString());
list.Add(pair);
}
public class myStruct
{
private string Key { get; set; }
private string Value { get; set; }
public myStruct(string key, string value)
{
Key …Run Code Online (Sandbox Code Playgroud) 我在一个bash shell中工作,我试图只打印第一次出现的字符串的行.例如,对于字符串' auir',如果我有文件myfile.txt并且它包含:
123
asdf
4wirajw
forauir somethingelse
starcraft
mylifeforauir
auir
something else
tf.rzauir
Run Code Online (Sandbox Code Playgroud)
我想输出" forauir somethingelse"
到目前为止,我使用命令
sed -n '/auir/p' myfile.txt
Run Code Online (Sandbox Code Playgroud)
这给了我所有这个字符串的出现.我怎样才能获得第一行' auir?如果它只是一个命令或命令管道,那就太棒了.
非常感谢任何见解.
我正在开发一个GUI,它能够通过datagridview操作xml文件,并将其保存到用户选择的目的地.该程序还有一个.exe.config文件,我也希望能够在datagridview中自由编辑,因为它比用户手动进入文件并相应地更改值更方便.
我已经尝试声明一个数据集,我最初认为.exe.config文件只是一个xml文件,但是这段代码不起作用:
dataSet1.ReadXml(configpath);
bindingSource1.DataSource = dataSet1.Tables[0];
dataGridView1.DataSource = bindingSource1;
Run Code Online (Sandbox Code Playgroud)
当我运行它时,datagridview是空的,我确认文件路径是正确的,当我调试代码时没有异常,而对于我在GUI中打开的其他xml文件与显示的数据完全正常.也许readxml()只支持..合法的xml文件而不是xml配置文件?我尝试使用谷歌搜索并寻找一些答案,但我得到的只是通过手动访问xml文件和更改值(我已经知道的东西)来更改设置的线程.我希望能够让用户做他们想要做的数据,然后保存它..exe.config设置也可能适用于其他程序,但它本质上是一个xml配置文件.我认为网络上没有太多关于这个特殊问题的原因,因为设置通常是静态的,如果它们被更改,手动操作非常容易.
总结一下,
我正在寻找一种方法,能够打开任何 .exe.config文件,在datagridview中显示它,允许用户能够操作里面的数据值,然后保存文件,覆盖以前的数据设置.
任何帮助表示赞赏.先感谢您!
编辑:我将上传一个我创建的xml文件的工作示例:我希望程序能够导航到.exe.config文件,然后打开它并让它显示如下,其中设置名称是列并且值位于datagridview的单元格中.不幸的是,我不能在我的家用电脑上做到这一点.
我想知道存在什么类型的库(许可或不许可),我可以找到在纬度/经度坐标和军事网格参考系统(mgrs)坐标之间转换的方法.我没有明确地寻找lat/long到UTM转换器,它必须是mgrs.我已经做了一些搜索和谷歌搜索,从我发现的,lat/long到UTM频繁出现,但似乎没有人有用于将lat/long转换为MGRS的库,反之亦然.
有谁知道我可以找到哪些库或地方可以做这样的事情?
谢谢,任何帮助表示赞赏.
tf.rz
我在我的程序中修复警告,显然xmlvalidating reader和xmlschemacollection已经过时了.问题是,我不太确定如何.这是尝试使用涉及xmlschemaset和xmlreader.create的新模板"模仿"先前的验证函数.我首先声明一个模式,然后使用targeturi字符串设置它,然后在设置验证事件处理程序时将其添加到模式集.我认为我的问题是设置读者和输入流.我知道如何使用xmlvalidating reader,但如果我想修复这些警告,那么这不是一个选项.这是代码和尝试.在测试期间,只使用了新的验证xml代码,旧的代码被注释掉了.
// New Validation Xml.
string xsd_file = filename.Substring(0, filename.Length - 3) + "xsd";
XmlSchema xsd = new XmlSchema();
xsd.SourceUri = xsd_file;
XmlSchemaSet ss = new XmlSchemaSet();
ss.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
ss.Add(xsd);
if (ss.Count > 0)
{
XmlTextReader r = new XmlTextReader(filename2);
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(ss);
settings.ValidationEventHandler +=new ValidationEventHandler(ValidationCallBack);
XmlReader reader = XmlReader.Create(filename2, settings);
while (reader.Read())
{
}
reader.Close();
}
// Old Validate XML
XmlSchemaCollection sc = new XmlSchemaCollection();
sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); …Run Code Online (Sandbox Code Playgroud) 我创建了一个程序,它能够通过datagridview修改.exe.config文件(app config)的内容,并在datagridview上显示键值对.问题是,我有一个保存设置,它将旧值替换为用户键入的新值.它保存,下次打开它时,文件将被覆盖,但当我尝试加载配置文件以更新用户设置已更改为时,我得到"另一个进程使用的文件"错误.
这是代码:
private XmlDocument m_XmlDoc;
private FileStream fIn;
private StreamReader sr;
private StreamWriter sw;
private OrderedDictionary m_Settings;
private void ProgramConfig_Load(object sender, EventArgs e)
{
try
{
loadconfigfile(GatewayConfiguration.Properties.Settings.Default.Config);
BindingList<KeyValueType> list = new BindingList<KeyValueType>();
for (index = 0; index < m_Settings.Count; index++)
{
list.Add(new KeyValueType(keys[index], values[index].ToString()));
}
var source = new BindingSource();
source.DataSource = list;
dataGridView1.DataSource = source;
}
catch (Exception ex)
{
textBox1.Text = ex.Message;
}
}
public void loadconfigfile(string configfile)
{
if (File.Exists(configfile))
{
m_XmlDoc = new XmlDocument();
GatewayConfiguration.Properties.Settings.Default.Config …Run Code Online (Sandbox Code Playgroud) 我正在开发一个允许用户操作xml文件的GUI.我在一个datagridview中显示xml文件,整齐地按列通过xml元素组织.我允许用户在我的项目中添加列作为扩展.该列被添加到数据集表中,然后更新到我用来显示xml文件的datagridveiew.我已经包含了用户添加组合框列来选择选项的能力,而不是像往常一样输入它们.对或错.然而,这就是问题所在.保存正常的列很容易.组合框柱很痛苦.
我有一个"保存组合框列"以将其更新为xml和"保存"按钮以保存在用户选择的目的地中.
我做了一些研究,似乎组合框类具有这样的功能,可以访问用户输入的组合框中的选择项.我们在哪里:
ComboBox box = new ComboBox();
box.SelectedItem;
Run Code Online (Sandbox Code Playgroud)
我尝试将它应用于组合框列类,但它没有这样的功能.因此,我无法弄清楚如何直接获取用户所选项的值.我也尝试过使用comboboxcell,但这并没有引导我到任何地方.我玩的那些课程都没有..."选定项目"功能,甚至谷歌也没有我的解决方案.=(我也尝试使用cell.value,但由于某种原因它是"null".即使用户选择框中的项目,它也不会保存到单元格的值中.
TLDR:我的问题很简单,如果可能的话,您如何获得对comboboxcolumn单元格所选项目的访问权限?此外,您如何确保项目值保存在单元格中?
提前致谢.我正在使用.NET 3.5 SP1,通过Visual Studio 2008 C#.
此致
tf.rz
我正在创建一个倒数计时器,允许用户选择一个有效的时间,一旦倒计时到零,它就会播放声音.
我已从System.Timers命名空间中实例化一个计时器并将其设置Interval为1秒.我将用户指定的时间转换为秒,并在1每次Timer.Elapsed函数命中时减小该值.一旦它达到零,这意味着倒计时已达到零,这意味着它是播放声音的时间.
但是,每当它没有达到零时,我减去时间值1,我也希望ProgressBar通过使用progressbar.Increment函数来递增.
不幸的是,每当我这样做时,它给了我一个与多线程问题有关的例外.我知道出了什么问题,但我不知道如何解决它.我是否需要timer.Elapsed在新线程上启动该功能?
错误是:
跨线程操作无效:控制'CountdownProgress'从其创建的线程以外的线程访问.
此外,欢迎任何关于更好的编程习惯的提示.非常感谢!
这是代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Timers;
using System.Media;
using System.Diagnostics;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form_CDA : Form
{
public Form_CDA()
{
InitializeComponent();
}
private bool m_CountdownActive; // declare global variables and instantiate timer.
private bool m_Cancelled;
public decimal …Run Code Online (Sandbox Code Playgroud) 我知道析构函数本质上是一个释放内存的函数,或者只要你完成它就会"清理".
我的问题是,正确的析构函数是什么?
让我给你看一些我所拥有的课程的代码:
#ifndef TRUCK_H__
#define TRUCK_H__
#include <iostream>
#include "printer.h"
#include "nameserver.h"
#include "bottlingplant.h"
using namespace std;
class BottlingPlant; // forward declaration
class Truck {
public:
Truck( Printer &prt,
NameServer &nameServer,
BottlingPlant &plant,
unsigned int numVendingMachines,
unsigned int maxStockPerFlavour );
~Truck();
void action();
private:
Printer* printer; // stores printer
NameServer* ns; // stores nameserver
BottlingPlant* bottlingPlant; // stores bottlingplant
unsigned int numVM; // stores number of vendingmachine
unsigned int maxStock; // stores maxStock
unsigned int cargo[4]; // stores the …Run Code Online (Sandbox Code Playgroud) 我有一个启动函数调用一个函数,该函数根据设置是否成功返回一个布尔值.如果成功则为True,如果失败则为false.我想在新线程上启动该函数,然后检查函数的状态:这是代码.
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(StartAdapter));
thread.Start();
Run Code Online (Sandbox Code Playgroud)
我的问题是,在这种情况下我将如何检查startadapter方法的返回状态?因为我的朋友告诉我,我不会知道返回状态,因为它是在另一个线程上启动的,但是尝试:
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(StartAdapter));
thread.Start();
bool result = StartAdapter();
Run Code Online (Sandbox Code Playgroud)
会调用该函数两次,这也是我不想要的.有没有人对此有所了解?
在这种情况下,我将如何检查startadapter函数返回的布尔值?
.NET 3.5
GUI有一个显示事件日志的按钮,这是另一个带有富文本框的表单.
我正在制作一个事件日志,告诉用户发生了什么.我遇到的问题是我不知道为什么我设置的事件处理程序在字符串更改时没有被触发.基本上,此表单有一个文本框,文本框设置为一个名为"活动"的字符串.此字符串会添加有关于状态和错误的各种消息.
但是,当字符串与其他消息连接时,事件不会被触发,也不会自动更新.我正在寻找这些事件发生时的实时更新.现在,我可以关闭表单,然后重新打开它,让它再次加载活动字符串,这是有效的,但有人可以解释为什么我设置的事件没有被触发?这是代码:第一位是我发布的新表单.第二位是具有字符串活动的类.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace StatusLog
{
public partial class StatusLogForm : Form
{
public StatusLogForm()
{
InitializeComponent();
}
private StatusLog statuslog = StatusLog.Instance;
private void StatusLogForm_Load(object sender, EventArgs e)
{
statuslog.ActivityChanged += new EventHandler(statuslog_ActivityChanged);
richTextBox1.Text = statuslog.Activity;
}
void statuslog_ActivityChanged(object sender, EventArgs e)
{
richTextBox1.Text = statuslog.Activity;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GDCanada.LCSS.VMF.ProtoVmf;
namespace StatusLog
{
public …Run Code Online (Sandbox Code Playgroud) 我有一个名为BottlingPlant的课程.我创建了以下头文件:
#ifndef __BOTTLINGPLANT_H__
#define __BOTTLINGPLANT_H__
#include <iostream>
class BottlingPlant {
public:
BottlingPlant( Printer &prt, NameServer &nameServer, unsigned int numVendingMachines, unsigned int maxShippedPerFlavour, unsigned int maxStockPerFlavour, unsigned int timeBetweenShipments );
void getShipment( unsigned int cargo[ ] );
void action();
};
#endif
Run Code Online (Sandbox Code Playgroud)
以下.cc文件:
#include <iostream>
#include "PRNG.h"
#include "bottlingplant.h"
BottlingPlant::BottlingPlant( Printer &prt, NameServer &nameServer, unsigned int numVendingMachines, unsigned int maxShippedPerFlavour, unsigned int maxStockPerFlavour, unsigned int timeBetweenShipments ) {
}
void BottlingPlant::getShipment( unsigned int cargo[ ] ) {
}
void BottlingPlant::action() {
} …Run Code Online (Sandbox Code Playgroud) 我想知道是否有一种C++方式打开文件并逐行读取输入.
我遇到了以下代码来完成任务:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ifstream myfile;
myfile.open ("example.txt");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我鼓励不要使用任何C函数或命令.
问题是,我的"example.txt"是一个字符串的形式,并使用str.c_str()是一个C函数,所以我想我有两种方法来解决这个问题.
有没有其他方法可以逐行读取文件中的输入?也许使用一些接受字符串作为文件路径参数的东西?有没有C++的做事方式?:)
或者,是否有另一种方法将字符串转换为const char*,这是myfile.open()函数需要的?
提前谢谢了!
编辑:我缺乏实践和研究使我认为c_str()是一个C函数,而事实并非如此.我很抱歉.既然不是我找到了答案.
c# ×8
c++ ×3
datagridview ×2
.net-3.5 ×1
bash ×1
combobox ×1
datasource ×1
destructor ×1
file-in-use ×1
file-io ×1
filepath ×1
header ×1
icollection ×1
java ×1
progress-bar ×1
sed ×1
selecteditem ×1
unix ×1
validation ×1
windows ×1
winforms ×1
xml ×1
xsd ×1