|
I've got a file with windows-1256 encoding. Would you tell me how I can read such file character by character? I don't want to read whole the file at once, it's important to read it character by character. But I don't know how to read a file with such encoding?!
Thank in advance!
|
|
|
|
|
Something like this should work:
string myFile = "";
System.Text.Encoding enc = System.Text.Encoding.GetEncoding(1256);
System.IO.Stream stream = System.IO.File.OpenRead(myFile);
System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
byte myByte; char myChar;
while(reader.PeekChar() != -1)
{
myByte = reader.ReadByte();
myChar = enc.GetChars(new byte[] {myByte})[0];
}
So basically, you're getting an Encoding object, passing in 1256 as the codepage. Then, reading each byte in from the stream one at a time, you're using the GetChars method to convert each byte and then grab a char from it. Hope that helps.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Thank you David! It helped!
|
|
|
|
|
Hi,
I'm a little confused about the datatable/dataview thing. I have a datatable (tCat) in a datagrid. I have a column (the primary key column) called file and a column called Customer (among other columns). Each record has it's own unique file number (in the file column), so that when the user clicks on a customer, the entire row is highlighted and the file number is recorded. My problem arises when a column other than File is sorted. I do the sort programatically, then try to re-select the file that was highlighted previous to the sort. But I can't figure out how to find the row index containing the integer (xFile) in the File column while the Customer column is sorted. Is it possible to have the tCat.DefaultView.Sort or DataView Sort set in one column while searching another?
Here, the table is first in Customer ascending order. After the sort to Customer DESC occurs I say:
tCat.DefaultView.Sort = "Customer DESC";
DataView dv = new DataView(tCat);
dv.Sort = "File";
row = dv.Find(xFile);
dg.Select(row);
Here, instead of finding the row that contains xFile, the xFileth row is highlighted.
I've also tried things like:
tCat.DefaultView.Sort = "File";
int xRow = tCat.DefaultView.Find("xFile");
dg.Select(xRow);
which results in what's on the screen being sorted by file order and the xFileth file highlighted.
This:
tCat.DefaultView.Sort = "Customer ASC";
int xRow = tCat.DefaultView.Find(xFile);
dg.Select(xRow);
results in an error (index = -1) since it searches the Customer column.
After days of trying to get this to work, I'm completely exhausted. Can anyone explain what I need to do to get this working?
Thanks so much!!!!!!!
Mel
|
|
|
|
|
It is frustrating that there isn't an easier way to do this, but what I've been doing is storing the last selected row (a reference to the actual DataRow object, not the row number) in the CurrentCellChanged event:
<br />
private void MyDataGrid_CurrentCellChanged(object sender, EventArgs e)<br />
{<br />
currentRow = MyDataView[MyDataGrid.CurrentCell.RowNumber].Row;<br />
}<br />
And then in the ListChanged event I search the newly sorted list and find the same row again:
<br />
private void MyDataView_ListChanged(object sender, ListChangedEventArgs e)<br />
{<br />
if (currentRow != null)<br />
{<br />
for (int i=0; i<MyDataView.Count; i++)<br />
{<br />
if (currentRow == MyDataView[i].Row)<br />
{<br />
MyDataGrid.CurrentRowIndex = i;<br />
break;<br />
}<br />
}<br />
}<br />
}<br />
Seems rather inefficient, but it does work for me.
|
|
|
|
|
You're wonderful! Thanks so much!!!
Mel
|
|
|
|
|
Hello im very new here and thought this was a great website/forum to help me with my very fustrating question. I have 3 drop down boxes (example,stage1,stage2 ID's) a Add button(btnadd) and a label(lbldesc). The drop down box are arrays with multiple selections.. example...
The dropdown boxes and selection:
[example] [stage1] [stage2]
1st selection [nike] [$100]
[shoe] [shoe 2] [$200] [Add]
[shoe 3] [300]
so on and so forth..
let say I choose Shoe Nike that cost 100.00
I have the Add button(btnadd) to post to the label on a form on the SAME page.
Form below the dropdownbox
description | Price
---------------------------------------------------
Shoe Nike | 100.00
(cmbostate + stage 2) | (stage 3)
---------------------------------------------------
Total |100.00
what is the easiest way to do this?
here is some snippets of code that i took off my source.
the event:
public void Page_Load(Object sender, EventArgs E) {
}
void btnAdd_Click(object sender, EventArgs e) {
lbldesc.Text = cmbostate.Text; (Ill put the rest of the code was just trying to see if it worked with the first dropdownbox)
}
my "add button":
<asp:button id="btnAdd" text="Add" runat="server" onclick="btnadd_Click">
my "label":
<asp:label id="lbldesc" runat="server">
my combo box:
cmbostate, stage 2, stage 3
i get a strange error telling me that:
error CS0246: The type or namespace name 'cmbostate' could not be found.
Anyone who can help me is greatly appreciated. Thanks!
|
|
|
|
|
Hello,
Is there a way of changing the font property for a specific Column in my DataGrid?
Thank you.
|
|
|
|
|
if u have given colulmnstyles, then u could jus give the font as wotever u want
like,
textColumnStyle.TextBox.Font = new Font("times New Roman",12,FontStyle.Italic);
|
|
|
|
|
Hi
Problem is, you can only see the difference in font when you click in the column cell, otherwise it does not change.
|
|
|
|
|
Hello everybody!
I created a database in MySQL, and successfully made connection from the C# application to MySQL. When I try to insert new record and update the database, it gave me an error message which is said
"ERROR [07006] Restricted data type attribute violation(SQL_C_NUMERIC)".
My code is
DataRow new_machine = main_form.db.Ds.Tables["machine"].NewRow();
new_machine["StockNo"] = stockno_txt.Text;
// Add a new machine record into the dataset
main_form.db.Ds.Tables["machine"].Rows.Add(new_machine);
// write it back to mysql database;
main_form.db.UpdateDatabase("machine");
The UpdateDatabase function is
public bool UpdateDatabase(string table)
{
System.Data.Odbc.OdbcDataAdapter adapter =
new OdbcDataAdapter("select * from "+table, _connection);
new OdbcCommandBuilder(adapter);
try
{
adapter.Update(_ds, table);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
_ds.Tables[table].AcceptChanges();
return true;
}
In the database, the field StockNo is declared as varchar(8) primary key.
Could somebody solve this problem for me please???
Thanks in advance!!!
Asura
|
|
|
|
|
Does anyone have an idea of how to make a tab page's title directly editable? I have asked on other message boards and no answers to date. Thanks in advance!
|
|
|
|
|
You have to extend the class... but I don't know how to do it precisely.
CodeProject's Server wrote:
HTTP/1.1 500 Server Error
|
|
|
|
|
Hi,
I want to write a C# windows application that reads some text from the interface of another (separate) application, and am looking for a few ideas as to where to start.
Specifically, I would appreciate some help with the following questions:
1) What is the best way to determine how the information I want is held in the other application?
2) What will probably be the best way to access the information I want.
For question 1, I suspect that the information I want it is in the equivalent of a label control, but am not sure. It could be a graphic object of some sort...
For question 2, I am guessing that I will need to use some Win 32 APIs to get a handle to the window I want, and then perhaps start capturing messages on it? (That of course assumes that the text I want to capture is neatly displayed in an object that can be accessed via its handle, however that might not be the case!)
Thanks in advance.
|
|
|
|
|
Hellow Every one,
Please tell me how to create mutltilines Crystal Report in Visual Studio .Net 2003 Crystal Report Desinger Panel.
Like this:
Column 1 Column2
________________________________
Dummy ID1 Dummy Data Line 1
Line2 of Column2
Dummy ID2 Dummy Data Line 1
Line2 of Column2
___________________________________
Please help Me. If you not getting my point, inform me.
|Muhamad Waqas Butt|
waqasb4all@yahoo.com
www.sktech.freewebspace.com
|
|
|
|
|
I want to get a list of installed applictions and display it in a form - the name and its icon. I have found out how to get the path. I know this much that all the application names can be found inside the registy HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\. How do i get the application icon because even though i have the application name. I dont have the path. There surely must be some way cause i can the icons in the Add Remove applet in the Control Panel? I cant seem to find anything abou this on the Internet!!!
|
|
|
|
|
It looks like there's a DisplayIcon value in some of the registry keys for the installed apps. You could use that. Otherwise, I believe the way that Windows does it is by looking for the EXE in the InstallLocation value, which all of those keys provide, and then grabbing the icon from it.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
Dont' know if this is the right forum but here goes !
I have an ActiveX control which I wrote (in VC6) and I am trying to use it in a C# Web App.
I have run it through AxImp.exe and now got a couple of dlls and a cs file.
Does any body know how I can now add the control to my C# page ?
Hope some body can help.
Cheers,
Users.
Can't live with 'em, can't kill em!
|
|
|
|
|
Are you using Visual Studio? If so, just add the ActiveX dll to the Visual Studio toolbox, then drop it on your form as if it were a standard .NET control, VS will do the AxImp for you.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
I am using VS 2003, when I add the ActiveX Control and build the project, it does not create anything and I can't access the control as it does not have a variable associated with it, any ideas ?
Cheers
Users.
Can't live with 'em, can't kill em!
|
|
|
|
|
Are you adding it to the VS toolbox and drop it on your form? Or did you just add it to the project references?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
Hi,
I added the activeX to the Toolbox and then dragged it onto the form but when I look as it's properties, it only shows the HTML properties, I can't see a way to give a variable which I can access from functions in the cs file.
Any ideas ?
Cheers
Users.
Can't live with 'em, can't kill em!
|
|
|
|
|
If you dropped it on the form, it created a variable for you. VS usually assigns the name ax[componentName][number], so if you dropped the WebBrowser control, it would generate a variable named axWebBrowser1.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
I tried adding the WebBrowser to the form, and nothing was created.
It does as you say if you drop the control onto a windows form but not a web form, any ideas ?
Users.
Can't live with 'em, can't kill em!
|
|
|
|
|
Lol...yeah, the WebBrowser controls is a Windows forms control, not a web forms control. That is where you're going wrong.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|