|
Hi friends,
Are there any methods to refuse changes of controls in a form ?
For example: I have a form that include one text box: txtNumber, and one Exit button.
At the first time, txtNumber.Text = "30" (When showing form)
Then, I changed the its value into "45". After that, I don't want to accept changes, I clicked the Exit button. Then txtNumber.Text is still "45". I want this value is "30".
Are there any method to refuse changes of TextBox in this case ?
Thanks and regards,
|
|
|
|
|
Simply set the ReadOnly property to true to prevent anybody from being able to change it via the UI.
|
|
|
|
|
allow to change (not Readonly)
|
|
|
|
|
Are you meaning that you want to be able to either commit the changes if a "save/Commit" button is pressed, and undo changes if the exit button is pressed?
If that is the case, your exit button could simply trigger the method you used to set the values when showing the form.
|
|
|
|
|
Thanks Ed Hill_5_,
That is my mean, I will try it
|
|
|
|
|
Please, in future, try to be clearer with your questions. There is no way, from your original post, that I would have been able to guess what your question actually was.
|
|
|
|
|
simply save the pre value and return it in case of pressing exit buttom.
|
|
|
|
|
i have the code below and want to convert the results in var rows to a DataTable
var rows = new List<Row>();
var sr = new StreamReader(dirCSV + fileNevCSV);
while (!sr.EndOfStream)
{
string s = sr.ReadLine();
if (!String.IsNullOrEmpty(s.Trim()))
{
rows.Add(new Row(s));
}
}
sr.Close();
|
|
|
|
|
It would obviously depend on what sort of object is your Row class. Maybe your best bet would be to create the DataTable first and then add each DataRow while reading the csv files, instead of creating the List<row>.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
|
Passing rows to the function below got it working.
public static DataTable ToDataTable<T>(this IList<T> data)
{
PropertyDescriptorCollection props =
TypeDescriptor.GetProperties(typeof(T));
DataTable table = new DataTable();
for(int i = 0 ; i < props.Count ; i++)
{
PropertyDescriptor prop = props[i];
table.Columns.Add(prop.Name, prop.PropertyType);
}
object[] values = new object[props.Count];
foreach (T item in data)
{
for (int i = 0; i < values.Length; i++)
{
values[i] = props[i].GetValue(item);
}
table.Rows.Add(values);
}
return table;
}
|
|
|
|
|
Best you would create a DataRow and add the content, then add it to IList<datarow> collection.
it will give a new extension method CopyToDataTable() which you can easily make conversion.
IList<datarow> iRows = new List<datarow>();
DataTable iTable = iRows.CopyToDataTable();
|
|
|
|
|
I have a project reading from XML file and than show it in datagridview. The code works great in win 7 and show the data as needed but when I tried to run in it in win xp, it reads from the file ok but only show the 1st column of the data. I don`t know what the problem is but it is not in the read process (I debugged it line by line) but ofcourse I`m missing something.
What can it be?
I don`t know it has any connection but I`m using win 7 64bits with VS 2008 32bit and win XP and VS 2008.
|
|
|
|
|
Without the relevant code fragment?
No idea at all...
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
The code to fill the datagridview is:
private void FillGridViewFromDataTable()
{
dataGridView.DataSource = m_table;
dataGridView.Columns["PrinterIP"].HeaderText = "IP כתובת";
dataGridView.Columns["PrinterIP"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["PrinterName"].HeaderText = "מזהה מדפסת";
dataGridView.Columns["PrinterName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["PrinterConnect"].HeaderText = "מחובר לרשת";
dataGridView.Columns["PrinterConnect"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["PrinterCounter"].HeaderText = "מונה";
dataGridView.Columns["PrinterCounter"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["PrinterPlace"].HeaderText = "מיקום";
dataGridView.Columns["PrinterPlace"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.RowHeadersVisible = false;}
I know that the reading from XML file is good, so something doesn`t work in the display part. As I said before on win7 it works perfectly.
Thank you
|
|
|
|
|
Looking at the header text, I suspect that culture/font may be the issue here.
|
|
|
|
|
Thanks for the quick answer. I tried to change it to english but it still doesn`t show the data correct. I may add that in the list I have 3 printers but it only shows 1 and not all the information needed. It shows only the printer IP (1st column). What else can it be?
|
|
|
|
|
Just as an experiment, change the AutoSizeMode to None for each column.
|
|
|
|
|
 Thanks for the help but still nothing. It maybe something with the entering the data into the datagrideview:
private void ReadFromXml()
{
List<Printer> PrinterList = new List<Printer>();
TextReader textReader = new StreamReader("xml\\PrinterDetailsLi.xml");
XmlSerializer deserializer = new XmlSerializer(typeof(List<Printer>));
PrinterList = (List<Printer>)deserializer.Deserialize(textReader);
textReader.Close();
Ping pingSender = new Ping();
IPAddress address = IPAddress.Loopback;
for (int i = 0; i < PrinterList.Count; i++)
{
PrinterList PList = new PrinterList();
IPAddress ip = IPAddress.Parse(PrinterList[i].PrinterIP);
PingReply reply = pingSender.Send(ip,5);
if (reply.Status == IPStatus.Success)
{
DataRow row = m_table.NewRow();
SNMP snmp = new SNMP(PrinterList[i].PrinterIP);
string Res = snmp.connectSnmp();
row["PrinterConnect"] = "כן";
row["PrinterCounter"] = Res;
row["PrinterName"] = PrinterList[i].PrinterName;
row["PrinterIP"] = PrinterList[i].PrinterIP;
m_table.Rows.Add(row);
PList.PrintConnect = 1;
PList.PrintCounter = Res;
PList.PrintIP = PrinterList[i].PrinterIP;
PList.PrintName = PrinterList[i].PrinterName;
PList.date = DateTime.Today;
PrList.Add(PList);
}
else
{
DataRow row = m_table.NewRow();
row["PrinterConnect"] = "לא";
row["PrinterCounter"] = "--";
row["PrinterName"] = PrinterList[i].PrinterName;
row["PrinterIP"] = PrinterList[i].PrinterIP;
row["PrinterPlace"] = PrinterList[i].PrinterPlace;
m_table.Rows.Add(row);
PList.PrintConnect = 0;
PList.PrintCounter = "--";
PList.PrintIP = PrinterList[i].PrinterIP;
PList.PrintName = PrinterList[i].PrinterName;
PList.date = DateTime.Today;
PrList.Add(PList);
}
}
XmlSerializer serializer = new XmlSerializer(typeof(List<Printer>));
TextWriter Pd = new StreamWriter(("xml\\PrinterDetailsLi.xml"));
serializer.Serialize(Pd, PrinterList);
Pd.Close();
}
What else can make it work on win7 but not on win XP?
|
|
|
|
|
And you're certain that the other columns are being populated properly in m_table? Try setting AutoGenerateColumns=true to see what it thinks the rows are in the DataTable .
|
|
|
|
|
Thank for the help, I have found the problem. The font color is white. All I had to do is change the color of the font.
Thank you for the help, You helped a lot!
modified 1-Aug-12 10:45am.
|
|
|
|
|
Nah, I don't think I helped that much. Kudos to you for figuring it out, and a healthy 5 from me (now don't forget to put Solved on your original post so that we know it's been solved).
|
|
|
|
|
Thank you until the next problem/question
|
|
|
|
|
Any idea how can I convert a string to array for the below example:
string name = "John,Calvin,Steve";
convert to
string [] arr = new string[] {"John","Calvin","Steve"};
|
|
|
|
|
Start here
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|