|
Yes, it's clear your method is better.
Previously I was setting Exists to false to "reset" it, so to speak. My thinking was, that if Sheet2Name != Null, then I wanted Exists to equal false unless Sheet2Name was present.
I can now see where I was going wrong, and how your approach is more efficient. I'll use it going forward.
Thanks again.
|
|
|
|
|
I think I see the problem.
The code I gave was to check if any of Sheet1Name , Sheet2Name or Sheet3Name are in the DB. Are you trying to check if all of non-null values of Sheet1Name , Sheet2Name or Sheet3Name are represented as rows in the DB?
If that is the case, you will need more complicated checking and keeping track of matching each of the sheet names separately.
Try something like:
The code as you have shown it will throw a NullReferenceException if any of Sheet1Name , Sheet2Name or Sheet3Name are null . You can use the ?? operator to make this safe:
bool Exists1 = Sheet1Name == null;
bool Exists2 = Sheet2Name == null;
bool Exists3 = Sheet3Name == null;
string Sheet1NameSuffix = (Sheet1Name ?? "") + "$";
string Sheet2NameSuffix = (Sheet2Name ?? "") + "$";
string Sheet3NameSuffix = (Sheet3Name ?? "") + "$";
foreach (DataRow row in dt.Rows)
{
string tableName = row["TABLE_NAME"].ToString();
if (tableName == Sheet1NameSuffix)
{
Exists1 = true;
}
if (tableName == Sheet2NameSuffix)
{
Exists2 = true;
}
if (tableName == Sheet3NameSuffix)
{
Exists3 = true;
}
}
if (Exists1 && Exists2 && Exists3)
{
MessageBox.Show("Match");
}
else
MessageBox.Show("No Match");
|
|
|
|
|
Matt, your approach looks far more "tidy" than mine
It works perfectly now. Thank you so much for your time, I've learnt a lot! Enjoying C# so much more than VBA, and your advice has helped with that too!
Thanks again!
|
|
|
|
|
Dear Expert,
I had successfull develop class for data collection however its display in command prompt, however how do i display this info in form textbox1, following is my class code
------------------------------------------------------------------------------------
using System;
using System.Management;
namespace remoteconnect
{
class Program
{
static void Main(string[] args)
{
ManagementScope scope =
new ManagementScope(
"\\\\computername\\root\\cimv2");
scope.Connect();
ObjectQuery query = new ObjectQuery(
"SELECT * FROM win32_computersystem");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
if (m.Properties["IsValid"].Value != null && m.Properties["IsValid"].Value.ToString() == "True")
m.Properties[""].Value.ToString();
}
}
}
}
----------------------------------------------------------------------------------------------------
In Form yet nothing but created texbox and button
----------------------------------------------------------------------------------------------------
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 remoteconnect
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
----------------------------------------------------------------------------------------------------------
would you please assist in regards....
|
|
|
|
|
You could use a ListBox [^] or similar control.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
in this case what will be the cript
to trigger the data in listbox
|
|
|
|
|
That is something you need to decide based on your program requirements. You could do it when the program starts and the form first loads, or you could do it in response to some external event such as a button press.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Did you want a click on the Button to trigger the reading of the Properties collection, and the writing of some data in each Property to the TextBox ? That's a guess
Let's say you name your Button "WriteQueryCollectionBtn," and your TextBox "PropertyTextBx" ...
In that case, perhaps your Button's Click EventHandler might look like:
private void WriteQueryCollectionBtn_Click(object sender, EventArgs e)
{
foreach (ManagementObject m in queryCollection)
{
if (m.Properties["IsValid"].Value != null
&& m.Properties["IsValid"].Value.ToString() == "True")
{
PropertyTextBx.Text += m.Properties[""].Value.ToString() + Environment.NewLine;
}
}
} Note that for this code to work in the Form, you would have to also reference the System.Management library with a 'using statement.
It's not clear here if you are going to "connect" and retrieve the data once, when the application starts (as you are doing now), or:
If you are going to want to pull-down the data every time the Button is clicked: my guess is that you'd want to refresh the data each time the Button is clicked, which will require you re-architect your code shown here.
The question here is: does the data change, or is it always the same ?
Again, this reply is pretty much a "blind guess" at what you might want to do. You'll have to be much more specific about your goals here, and the nature of the data, if you want more specific feedback.
good luck, Bill
|
|
|
|
|
I have a problem reading lines and showing them from a text file in a ListBox using Windows Form Application.
I made some code but now I'm stucked in a place where I made a comment.
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.IO;
namespace LlogariaBankare
{
public partial class KlientForm : Form
{
public string pathi = "Klientet.txt";
public KlientForm()
{
InitializeComponent();
}
private void KlientForm_Load(object sender, EventArgs e)
{
this.ShtoButon.Enabled = true;
this.AzhuroButon.Enabled = false;
this.FshijButon.Enabled = false;
}
private void ShtoButon_Click(object sender, EventArgs e)
{
StreamWriter swKlientet = new StreamWriter(pathi, true);
swKlientet.WriteLine(emriBox.Text + "\t" + mbiemriBox.Text + "\t" +
datelindjaBox.Text + "\t" + vendlindjaBox.Text + "\t" +
xhirollogariaBox.Text + "\t");
swKlientet.Close();
}
private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
like StreamWriter you can use StreamReader to read text files.
Check the examples here MSDN StremReader class[^]
Jibesh.V.P
India
|
|
|
|
|
You should not be putting the file reading code in the SelectedIndexChanged event or it will be repeated every time the selection changes. You should initialise your ListBox after the form is first loaded, or in some other method.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
OK, now i konw how to read a text file and put it in a listbox, but the problem is that when I type a new line it doesn't show me that new line in Listbox until i debug again the form.
I solved the problem creating a method on form load.
Do I need to create a new method to reload the text file again or what ever.
Cheers in advance for your reply.
|
|
|
|
|
dr_iton wrote: Do I need to create a new method to reload the text file again or what ever. Not necessarily, but you do need to create a method that can add any extra information as it is entered into the program. These controls can be updated at any time by adding or removing entries from them, you do not need to reload them from the beginning.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
After all I have the following problem.
I can remove the lines from listbox, but those lines are not deleted from text file, how to delete a specific line from a text file.
Cheers in advance for your reply.
|
|
|
|
|
dr_iton wrote: I can remove the lines from listbox, but those lines are not deleted from text file Why would you expect them to be, since there is no connection between the two?
The easiest solution would be to recreate the text file from the contents of the ListBox , either when the content changes, or when the program terminates.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I created a method to show the items in ListBox in Form 1, like this
string linjaListBox = this.ListBox.SelectedItem.ToString();
string emriPjesa = linjaListBox.Split('\t')[0];
string mbiemriPjesa = linjaListBox.Split('\t')[1];
string datelindjaPjesa = linjaListBox.Split('\t')[2];
string vendlindjaPjesa = linjaListBox.Split('\t')[3];
string xhirollogariaPjesa = linjaListBox.Split('\t')[4];
this.emriBox.Text = emriPjesa;
this.mbiemriBox.Text = mbiemriPjesa;
this.datelindjaBox.Text = datelindjaPjesa;
this.vendlindjaBox.Text = vendlindjaPjesa;
this.xhirollogariaBox.Text = xhirollogariaPjesa;
indeksLista = Convert.ToInt32(ListBox.SelectedIndex.ToString());
In the next form I used three of TextBoxes from first Form such as emriBox,mbiemriBox and xhirollogariaBox.
How to show the text in those three TextBoxes in form2 if I select a row in ListBox from Form1.
|
|
|
|
|
Why not just:
string linjaListBox = this.ListBox.SelectedItem.ToString();
string[] items = linjaListBox.Split('\t');
this.emriBox.Text = items[0];
this.mbiemriBox.Text = items[1];
this.datelindjaBox.Text = items[2];
this.vendlindjaBox.Text = items[3];
this.xhirollogariaBox.Text = items[04];
indeksLista = ListBox.SelectedIndex;
Form2.emriBox.Text = items[0];
Form2.mbiemriBox.Text = items[1];
Form2.xhirollogariaBox.Text = items[4];
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
OK, my Form2 is named GjendjaForm, and after I rename Form2 with GjendjaForm it shows me the following errors.
GjendjaForm.emriBox is inaccessible due to its protection level
GjendjaForm.mbiemriBox is inaccessible due to its protection level
GjendjaForm.xhirollogariaBox is inaccessible due to its protection level
also it says that:
Error 3 An object reference is required for the non-static field, method, or property 'LlogariaBankare.GjendjaForm.mbiemriBox' C:\Users\Driton Gashi\Documents\Visual Studio 2008\Projects\LlogariaBankare\LlogariaBankare\KlientetForm.cs 112 17 LlogariaBankare
|
|
|
|
|
You need to make your textboxes public, or add some properties or delegate events that allow the transfer of data between the two classes. In the second message you are trying to call a non-static method of the class without an object reference. This is basic C# object handling which you really need to understand before you go much further in this development project. Take a look at these samples[^] for further details.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I am displaying a datagridview using
dataGridView1.DataSource = dv;
When the dgv is displayed only the top left cell has a visible value. However when I click in other cells, the data in that cells becomes visible.
Any ideas why this could be happening. Thanks.
|
|
|
|
|
1)Do use change any other properties of your dgv ?
2) What type is the "dv" that you set as DataSource?
Although I work with dgvs I never had this bug.
|
|
|
|
|
1) No, I just placed the dgv on the form, but changed no properties.
2) dv is a dataview. I have changed changing the source to a datatable and the same thing happens.
I have tried using my code in a new project, and it works fine.
|
|
|
|
|
May be silly, but since it works on a new project, try to use "rebuild solution" in your visual studio.
Other than that I have no clue.
|
|
|
|
|
I tried that and it didn't work. I just don't understand why only the selected cells become visible I put a lot of work into the form and I'd prefer not to do it all again, so if anyone has any ideas - please let me know! Thanks.
|
|
|
|
|
just delete control from the form and try to add with same name to preserve the coding done on the variable. VS behaves odd at times. when this happens i used to close all the visual studio and start over again. will work like a charm.
Jibesh.V.P
India
|
|
|
|