|
Hi
As far as I know a data table is not a cursor (but as its name says is a table or at least a snapshot of a table) then there's no current row when you are working with a table.
If you like to find a row within a table you can use its defualt data view and use its Find method which has some overloads.
(for example myTable.DefualtView.Find(key))
You can have a local variable that works as a bookmark and shows the current row index then you can retrieve current row using DataTabe.Rows indexer for example
int currentRow=1;
DataRow row=myTable.Rows[currentRow];
then you can implement some methos to navigate through your data table (currentRow+=1,currentRow-=1)
Good Luck
|
|
|
|
|
mmm
It seems that I know even less than I thought.
I have tried looking at this from all angles - to no avail.
Let's say that you are using the customer table in the Northwind DataBase.
You add a new customer. That customer is appended to the end of the table.
But I want to refresh the dataSet so that it is :
a. In Alphabetical order again. - this I can do. But it takes the focus back to the first row in the Data Set.
B. The row that is displayed on the form is the row that I have just added. "Eg Smith" and the next button will then display the row that follows Smith.
It is this latter aspect that I find hard to accomplish. If I can do this, then I feel certain that I can do the rest of what I want.
Any specific clues on this would be greatly appreciated.
John Martin
|
|
|
|
|
Hi
You can hold the key of a new row that has been added and set your current row to this new row (using sort and find metohd)
if you sort your table using its default view property (myTable.DefaultView.Sort="Field1 DESC,Field2"; ) then the next button will show the next record according to sorted key.
But I have a question to ask, if there's only one record showing to user each time , why do you load all the data to a data table ? you can load a record whenever it's needed.
for example if you have a code field that you want to use as your sort key you can get the next record using :
<br />
SELECT TOP 1 * FROM myTable WHERE code>@currentCode ORDER BY CODE<br />
and you can get the previous record using :
<br />
SELECT TOP 1 * FROM myTable WHERE code<@currentCode ORDER BY CODE DESC<br />
Getting the first and last records is also very easy.
<br />
SELECT TOP 1 * FROM myTable ORDER BY Code
SELECT TOP 1 * FROM myTable ORDER BY Code DESC
<br />
The good news is that you can find your record before loading it to your app thus only the needed data is loaded.
Regrads
|
|
|
|
|
Hi again and thanks for your input.
The points you make about using seperate select statements is a good one.
I also tried the first method and your suggestions are good. With the find method indeed finds the row index. but how do I get the form to display the contents of the row that I have "Found" - for instance I may be looking at the first row of Customers. I want to look for the Row that has an CustomerID of "SMITH". IF I do a find in it - it will return a value that gives me the row index of the DefaultView, but how do I move the focus to that row so that is the row that is displayed?
Again thanks for all your help
jm
John Martin
|
|
|
|
|
Hi,
I have found a few (4+) bugs in VS2005 C# that I worked around and I seem to have found another that I can't workaround ( but can drop if I really want/need to ).
Can I have some feedback on the pro's and con's of installing the beta SP1 please.
Thanks,
Glen Harvy
|
|
|
|
|
please provide your Feedback directly to MS on connect
'A programmer is just a tool which converts caffeine into code'
|
|
|
|
|
You might be aware that whenever the user clicks on the column header of a filled data grid view, the rows of the data grid view or sorted according to that column values.
How can i prevent this. I don't want the user to be able to sort the values.
|
|
|
|
|
just use the following code
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
Hope that works for u...
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
Just what i wanted.
Thanks a lot Pramod. It worked.
|
|
|
|
|
Tearing my hair out here.
I remember seeing an artical using the .net 2.0 WebBrowser combined with a tree control to decompose a web page or view xml conversion results in a tree.
Been looking all day stumbling across lots of other stuff that I book marked.
Thanks
|
|
|
|
|
Hello everyone!
OK, I need to write and read integers on a file... What's the best way to do this in C#? Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Your subject talks about a specific way of doing this. Is that the exact way that you want to do it? Or would using a BinaryWriter be ok?
---
b { font-weight: normal; }
|
|
|
|
|
Hmm... Didn't know about that class! Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Hello,
Im looking for a way of changing the keyboard layout for a user-defines window.
Any one know how to achieve it ? or any software that does it ?
|
|
|
|
|
Hi
I don't know if there is a way to change your keyboard layout using the framework (managed code) but I think in famework 1.1 you should use the windows API
to do so first declare following API function in your class
<br />
[DllImport("user32")]<br />
private static extern int LoadKeyboardLayout(string pwszKLID,long flags);<br />
Then you can call this function to change the keyboard layout.
pwszKLID is a pointer to a buffer that contains the locale name.You should know the locale ID for your prefered language ( I think that you can find them on MSDN)
I don't know what are the flags ( you can find its values on MSDN) but we are using 1 and it's working fine.
Good Luck
|
|
|
|
|
I have a form with a picture box and i'm tring to draw an rectangle or an image on the picturebox.image or on the form (thou i'd prefer on the picture box ). the picturebox is sent to back and the form has 70% opacity
this is what i wrote:
myPoint.X = X;
myPoint.Y = Y;
Rectangle rect = new Rectangle(X,Y,10,10);
Image img = Image.FromFile("C:\\Project Data\\dot.bmp");
e.Graphics.DrawImage(img, myPoint);
pictureBox1.Refresh();
e.Graphics.FillRectangle(brush, new Rectangle(myPoint, new Size(10, 10)));
this.Refresh();
and it still doesn't work
can you tell me what i'm doing wrong, and if i cand draw on the picture box.image and how
rzvme
|
|
|
|
|
You need to draw onto the bitmap, how is this code working ? Is it inside the picture box ? If not, why are you calling DrawImage ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
it would be great if i could paint on the picture box...but i dont know...that code draws on the form.
rzvme
|
|
|
|
|
I am using the paint event of the picture box to draw on it and i'm calling the refresh method on it from the form
rzvme
|
|
|
|
|
Hey
Can somebody please tell me how to make code that opens a specifik file with Windows media player from a specifik folder on a Pocket pc 2003?
I hope someone can help me...
|
|
|
|
|
I have an XML definition which I want to incorporate as a resource within my application. I need to be able to get the XML definition out of the resource file, and get it into a stream so that it can be fed into the XmlSerializer.Deserialize() method.
I am getting the data into a string using ResourceManager no problem. I tried a MemoryStream, but I get an error that there is invalid XML in the header with the following code:
ResourceManager manager = new ResourceManager( typeof( SmartClient.buttonDef ) );
string item = manager.GetString( "buttonDef" );
MemoryStream stream = new MemoryStream();
UnicodeEncoding uniEncode = new UnicodeEncoding();
stream.Write( uniEncode.GetBytes( item ), 0, item.Length );
XmlSerializer serializer = new XmlSerializer( typeof( DefinitionFile ) );
file = ( DefinitionFile )serializer.Deserialize( stream );
Does anyone have a suggestion on how to go about doing this so that the Deserialize call works correctly??
|
|
|
|
|
I'm writing a program that has multiple groups of multiple radio buttons on a form. When a radio button is clicked, I use for loops to determine if one radio button from each group has been selected. If it is then I execute the following code:
for (int i = 0; i < 4; i++)
{
this.rating[i].Enabled = false;
this.rating[i + 4].Enabled = true;
this.radioGroup[i].Enabled = false;
this.radioGroup[i + 4].Enabled = true;
}
All is well and good, except when any radio button in a 3rd group is clicked last and it reaches the line this.radioGroup[i].Enabled = false; the program jumps out of my loop and executes the code as if a radio button has been clicked. radioGroup is an array of panels and this only occurs when I click the 3rd group of radio buttons. Also, it gets through fine during the second execution of the code and returns to where it left off the first time through.
My question is why would the radio button event handler be fired when I disable a panel from my form? Has this happened to anyone else and if so, what can I do to fix it?
Thanks in advanced for the help, and this is my first posting here on CP
~Yeck
|
|
|
|
|
Have you single stepped through your code at the time you set the enable bit? If so does the step path take you through a section where you set a value on the radio button?
|
|
|
|
|
I have stepped through the program. The code is within a handler for radioButton clicks and directly after disabling the panel it jumps to the beginning of the handler. The thing that disturbs me the most is that it only occurs when one of the radio buttons from the third row is clicked last, and yet the radio buttons are initiallized within a for loop.
|
|
|
|
|
Are any of the radiobuttons being disabled selected? IF so, I'd assume disabling them is also unselecting them, and the checked event handler fires for both selection and unselection of the button.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|