|
Hi, I'm working with a application and I've added support for scaling window so it can fit different resolution.
One control I'm having problem with is the TabControl. I've used the fixed style and set the ItemSize (had to do that to get the correct look with horizontal text). But now the control refuses to change it's ItemSize when I'm scaling the window.
Anyone know of a way to change the ItemSize property dynamically on a tabcontrol?
Regards
/Mike
|
|
|
|
|
this.tabControl1.ItemSize = new Size(Convert.ToInt32(this.Width * 0.1), Convert.ToInt32(this.Height * 0.1));
(Just a random number to have this, The tabcontrol is in Fixed Size mode) and have used the above code in Resize event.
|
|
|
|
|
HI
This is the format of my text file
i have to show data from text file to List View
a.txt
--------
1,2,3,4,5,6,7,8
9,10,11,12,13,14,15,16
17,18,19,20,21,22,23,24
Here 1 will come in one coulmn and 2 will come in another coulmn
In my winform there are 8 Columns in ListView
it should display all the contents
code needs
regards
sanjeev
|
|
|
|
|
You might try something like this:
using(StreamReader sr = new StreamReader("a.txt"))
{
string line = sr.ReadLine();
while (line != null)
{
ListViewItem newItem = new ListViewItem();
string[] subItems = line.Split(',');
for(int i=0;i<subItems.Length;i++)
newItem.SubItems.Add(subItems[i]);
listview.Items.Add(newItem);
string line = sr.ReadLine();
}
}
</code>
/cadi
24 hours is not enough
|
|
|
|
|
hi
your code is working fine
but in first column it takes blank space
it starts print after first column can u change ur code
regards
sanjeev
|
|
|
|
|
Hi!
to be honest, id did not test the code... i just wrote in in the editor...
should be like this:
string[] subItems = line.Split(',');
if (subItems.Length > 0)
{
ListViewItem newItem = new ListViewItem(subItems[0].Trim());
for(int i=1;i<subItems.Length;i++)
newItem.SubItems.Add(subItems[i].Trim());
}
this should work better (not testet too )
/cadi
24 hours is not enough
|
|
|
|
|
Hi
Thanks for your answer
Its working fine
StreamReader sr = new StreamReader("job.txt");
string line = sr.ReadLine();
line=line.Trim();
while (line != null)
{
ListViewItem newItem=null;
string[] subItems = line.Split(',');
if (subItems.Length > 0)
{
newItem = new ListViewItem(subItems[0].Trim());
for(int i=1;i<subItems.Length;i++)
newItem.SubItems.Add(subItems[i].Trim());
}
lbo_BD_historyEntry.Items.Add(newItem);
line = sr.ReadLine();
}
Again i have another question I have to write 10 lines in job.txt after 10 lines it will copy all the contents to oldjob.txt
and job.txt will delete all the contents it will again start storing new 10 lines. Job.txt has limitation of storing only 10 lines.
oldjob.txt will store all the contents
could u pls tell me
one more question i have
suppose my column name is name i have to search name in name column
name is suppose sanju
it will search from oldjob.txt and job.txt from both the files
and will display the result in listview
could u pls tell me how to make for optimazation purpose
regards
sanjeev
|
|
|
|
|
Hi Sanjeev,
first one comment to your code. You should either use a using block around the usage of the StreamReader or at least close it after use.
I hope the code below gives you some idea on how you could do it.
The performance will decrease by every entry made to "oldjob.txt" since you can only search seqentially. If you exceed several thousand lines you should move to some database driven model.
using System;
using System.IO;
using System.Collections;
namespace CodeProject
{
public class AppendAndMove
{
private const int LIMIT = 10;
private int m_LinesWritten = 0;
private string m_File1 = @"job.txt";
private string m_File2 = @"oldjob.txt";
public AppendAndMove()
{
if (File.Exists(m_File1))
{
using(StreamReader sr = new StreamReader(this.m_File1) )
{
while (sr.ReadLine() != null)
this.m_LinesWritten++;
}
}
}
private void MoveContent()
{
using(StreamWriter sw = new StreamWriter(this.m_File2,true))
{
using(StreamReader sr = new StreamReader(this.m_File1) )
{
string line = sr.ReadLine();
while (line != null)
{
sw.WriteLine(line);
line = sr.ReadLine();
}
}
}
File.Delete(this.m_File1);
}
public void AddLine(string line)
{
using(StreamWriter sw = new StreamWriter(this.m_File1,true))
{
sw.WriteLine(line);
m_LinesWritten++;
}
if (m_LinesWritten == LIMIT)
{
MoveContent();
m_LinesWritten =0;
}
}
private string[] FindValueInFile(string fileName,int columnIndex, string value)
{
ArrayList result = new ArrayList();
if (File.Exists(fileName))
{
using(StreamReader sr = new StreamReader(fileName) )
{
string line = sr.ReadLine();
while (line != null)
{
string[] columns = line.Split(',');
if (columns.Length > columnIndex)
{
if (columns[columnIndex] == value)
{
result.Add(line);
}
}
line = sr.ReadLine();
}
}
}
return (string[]) result.ToArray(typeof(string));
}
public string[] FindValue(int columnIndex, string value)
{
ArrayList result = new ArrayList();
result.AddRange(FindValueInFile(this.m_File1,columnIndex, value));
result.AddRange(FindValueInFile(this.m_File2,columnIndex, value));
return (string[]) result.ToArray(typeof(string));
}
[STAThread]
static void Main()
{
AppendAndMove testClass = new AppendAndMove();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
Random rnd = new Random();
for(int i=0;i<100;i++)
{
sb.Length=0;
for(int t = 0;t<8;t++)
{
sb.Append(rnd.Next(1,100));
if (t != 7)
sb.Append(",");
}
testClass.AddLine(sb.ToString());
}
string[] foundLines = testClass.FindValue(2,"50");
foreach(string s in foundLines)
System.Console.Out.WriteLine(s);
}
}
}
/cadi
24 hours is not enough
|
|
|
|
|
Hi cadi,
Thanks for your help.
can you little bit change your code
my job.txt file is given below
-----------------------------
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
5,6,7,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
here in this file total rows is 15 .
If the file length is greater then 10 rows then all the previous records will appended to oldjob.txt
In your program you have created random no and stored in oldjob.txt
I want that all the previous records more then 10 lines will be copied to oldjob.txt.
File length should not greater than 10 rows or 10 lines.
If currently 5 rows to be displayed but job.txt aleardy has 10 rows. then 10 rows will be appended to oldjob.txt
can you do that
thansk again for your kind help
regards
sanjeev
|
|
|
|
|
Hi,
Job.txt can store only 10 rows suppose job.txt has 14 rows previous 10 rows will be tranferred to oldjob.txt and last foru rows will be stored in job.txt
actaullty it counts in contructor how many rows are present in job.txt
here is the code
public Form1()
{
//
// Required for Windows Form Designer support
//
if (File.Exists(m_File1))
{
using(StreamReader sr = new StreamReader(this.m_File1) )
{
while (sr.ReadLine() != null)
this.m_LinesWritten++; //total no of rows in job.txt
MessageBox.Show(this.m_LinesWritten.ToString());
}
}
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
private void button11_Click(object sender, System.EventArgs e)
{
ArrayList ob=new ArrayList();
if (this.m_LinesWritten >= LIMIT)
{
MessageBox.Show("Reached limit");
StreamReader sr = new StreamReader("job.txt");
string line = sr.ReadLine();
line=line.Trim();
int count=1;
int i;
string fileName = "temp1.txt";
while (line != null)
{
string[] subItems = line.Split(',');
ListViewItem newItem=null;
string[] subItems1 = line.Split(',');
if (subItems.Length > 0)
{
newItem = new ListViewItem(subItems1[0].Trim());
if(count>10 )
{
for( i=0;i<subItems.Length;i++)
{
newItem.SubItems.Add(subItems1[i].Trim());
ob.Add(subItems1[i].Trim());
}
}
}
if(count>10 )
{
listView1.Items.Add(newItem);
}
line = sr.ReadLine();
count=count+1;
}
int l=ob.Count;
MessageBox.Show(ob.Count.ToString());
writer = File.AppendText(@"oldjob.txt");
for(int m=0;m<l;m++)
{
writer.Write((string)ob[m] + ",");
}
writer.Close();
}
here problem is that oldjob.txt stores all in one line
here is the structure of oldjob.txt
-------------------------
6,7,8,9,10,11,13,6,7,8,9,10,11,14,
i want in this structure
6,7,8,9,10,11,13
6,7,8,9,10,11,14
can you modify the above given code
regards
sanjeev
Everything is possible
|
|
|
|
|
Hi
i would to customise the Size of a Button on a Form by mouving the Mouse(like designing Forms and Controls in VS)
an idea?
Thanks
simo
|
|
|
|
|
In runtime ?,you could override the mousedown event.
|
|
|
|
|
I am using Interop.Word.dll COM object to create a spell ckecking tool for a c# web application.
It works fine from my localhost, however when I run the application remotely from another web server I get the following exception error.
System.Runtime.InteropServices.COMException: COM object with CLSID {000209FF-0000-0000-C000-000000000046} is either not valid or not registered.
Also, I linked to my localhost from another PC (MS Word is installed in both machines) and it didn't work either.
The problem seem to be when accessing the object remotely.
Any help will be much appreciated
Thanks
Tony
|
|
|
|
|
|
if i set a my own 256 color to this.cursor, it is converted in a full black color.
How can i correctly load a 256 color in my application?
|
|
|
|
|
Hi all,
I have a simple login form to my application which displays textboxes for username, password and server (tabindexes in the order given). The user name and server values get set from the last login if they have been saved to a config file. In the form load event I check to see if the user name has been populated and if so I would like the password box to have focus e.g.
private void frmLogin_Load(object sender, System.EventArgs e)
{
if (txtUserName.Text.Length > 0)
txtPassword.Focus();
}
This doesn't work however. If I capture the result of the Focus call it returns false. Am I missing something simple here? I don't want to go the route of programatically changing the tab order.
|
|
|
|
|
or try
this.ActiveControl = txtPassword;
My Blog ^
|
|
|
|
|
|
Hello need help
How to retrive user log and log off time from active directory,
|
|
|
|
|
Rumor has it the last logout time is not replicated in Active Directory...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for your response how can i find log in time
|
|
|
|
|
Hi friends!
How can I create a self-executing file from within a C# application? What exactly I want is that I have a data file incorporating data which can be changed by the user. I want to give an option to the user to create a self-executing file from within my C# application which will contain that data file and in fact the self-executing file will itself be created with that data file name. One thing to remember - the data file name may change and the data may also change. So the self-executing file must be a flexible system.
Subsequently, one should be able to run this data file through that self-executing file even though my C# application might not be available.
Thanks in advance and regards!!!
|
|
|
|
|
Create your "self executing" program as a standalone program reading its data out of a Win32 resource block.
Now embed this self executing application in your main program. When needed get the executable out of the resource manager, write it to disk with the appropriate name and add the data file to it using the Win32 API to update resource blocks.
Maybe you can also use a standard .NET resource - I never tried, but if it is possible it's probably easier than dealing with Win32 API.
|
|
|
|
|
I have seen so many browsing LDAP applications. However, i can't find a property returned from DirectorySearcher.FindAll() that gives me the user's password ? I have some reason that i need to get into the remote AD to get a particular user name and his/her password. But it seems that I can't easily get it T_T
Please help
|
|
|
|
|
For security reasons it is not possible to retreive the password from the AD.
If youl realy need access to the passwords you would have to write an AD-Plugin that captures password changes (and only changes).
This i a little like replacing the GINA and capturing passwords during login.
And btw. this is faaar away from easliy
/cadi
24 hours is not enough
|
|
|
|
|