|
I believe this is because the RowCount property is related to the rows visually represented by the DataGridView control. According to your steps, after the constructor has run you have a DataGridView control and a DataSource attached to it that is filled with data, but the DataGridView control hasn't done it's visual rendering yet. If you check the property after the DataGridView has been rendered and displayed at least one time, you should get the expected value. Try placing an event handler on the Form.Shown event and then put a break point in the handler and check the RowCount property.
Hold on a second here... Don't you think you might be putting the horse ahead of the cart?
|
|
|
|
|
That is what I had in mind as well. Let us see if we get a confirmation.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Hey Guys,
Can any one tell how can we make use of form in windows application for creating object explorer , query analyzer and registered services windows of sql server management studio ? And it should also have the same kind of functionality what we get in sql server management studio.
Thanks,
Vikas
vikas da
|
|
|
|
|
How do I select distinct rows from a DataTable?
|
|
|
|
|
fill it distinct !!!!
|
|
|
|
|
By "DataTable", do you mean a table in a database?
In my opinion, there should be no identical rows (rows with identical values for ALL fields) in a database table. So please clarify your question a bit. Thanks!
|
|
|
|
|
By definition no real database (as opposed to using excel or similar as a datasource) will allow two identical records in all fields: The primary key must be unique. It is perfectly possible (but very annoying) to have all other fields identical between two or more records, though. Software should cope with it (as well as try to prevent it), because people will make mistakes...
I think the OP is talking about using a DataTable object, though.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Assuming that you want to select specific rows from a DataTable object rather than a database table, you can use the DataTable.Select method[^]
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
hello every1,
M new to this site so dont know how to post a query here if m wrong do correct me.M making a project in Csharp.Net on batch image processing.I can display multiple images n select it in check box but instead of checkboxes i want the thumbnail of the images to be displayed in the box.Can somebody please help.Thanks in advance......Here is the code that i coded in MS Visual Csharp 2008 express edition
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
Dictionary<string, string> ImageList = new Dictionary<string, string>();
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.ResizeRedraw, true);
}
private void button3_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
DirectoryInfo FileDirectory = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
FileInfo[] FileJpg = FileDirectory.GetFiles("*.jpg");
FileInfo[] FileGif = FileDirectory.GetFiles("*.gif");
FileInfo[] FileBmp = FileDirectory.GetFiles("*.bmp");
FileInfo[] FileTif = FileDirectory.GetFiles("*.tif");
FileInfo[] FilePng = FileDirectory.GetFiles("*.png");
foreach (FileInfo File in FileJpg)
{
ImageList.Add(File.Name, File.FullName);
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FileGif)
{
ImageList.Add(File.Name, File.FullName);
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FileGif)
{
ImageList.Add(File.Name, File.FullName);
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FileTif)
{
ImageList.Add(File.Name, File.FullName);
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FilePng)
{
ImageList.Add(File.Name, File.FullName);
checkedListBox1.Items.Add(File.Name);
}
}
}
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
pictureBox1.ImageLocation = null;
String s = folderBrowserDialog1.SelectedPath.ToString() + checkedListBox1.SelectedItem.ToString();
MessageBox.Show(s.ToString());
pictureBox1.ImageLocation = s;
}
private void Form1_Load(object sender, EventArgs e)
{
checkedListBox1.CheckOnClick = true;
}
private void checkedListBox1_SelectedIndexChanged_1(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile(Path.Combine(folderBrowserDialog1.SelectedPath, checkedListBox1.Items[checkedListBox1.SelectedIndex].ToString()));
}
private void label2_Click(object sender, EventArgs e)
{
}
}
modified on Thursday, January 7, 2010 9:17 AM
|
|
|
|
|
Please edit your post and surround the code in the '
' tags, this will format it so it will appear to others just as you normally see it in Visual Studio. You can put the tags around the text yourself or highlight the text and then click the 'code block' option above the edit window.
Also, what control are you using for displaying the images?
Hold on a second here... Don't you think you might be putting the horse ahead of the cart?
|
|
|
|
|
i didnt get u @Ben what control means?????
|
|
|
|
|
Use <pre> tags to surround code blocks.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I believe you mean <pre>code here<pre/> tags.
|
|
|
|
|
I think you should restate your question as it's not terribly clear. You want to provide a way to select multiple images for batch processing, and you want to display thumbnails, but it all stops there for me. What are you having difficulty with? Drawing images to the screen? If so, have a look at the Graphics class.
|
|
|
|
|
till now i have put a checkbox and i can select multiple images through it n it is displayed in the preview box but instead of seeing just the name of the images in the checklist box i want the thumbnails of the images to be displayed along with the check button
|
|
|
|
|
It seems that you want to use a CheckedListBox and display thumbs instead of filenames. To do so I believe you must use the OwnerDraw method. Try googling it though - surely many have done the same or something similar before you.
|
|
|
|
|
|
If i click on add photos a new window pops to select a particular folder in whcih images are present.But i cannot select the particular image i have to select the whole folder and the names of these images are then displayed in the checklist box.I want the thumbnails of these images to be displayed in this box.When i will select a particular image it will be displayed in the preview box,There is also a problem here i cannot c the whole image but only a part of it.......I hope this will help u to clear my doubt.
|
|
|
|
|
Hi,
one way to get what you want is this:
1. define a little MyImage class, containing a file name, a bitmap, a selected flag.
2. use a regular ListBox; it can show a collection of items of any type you choose (not just strings), so use it to hold instances of MyImage.
3. provide your own DrawItem handler to paint the MyImage any way you like (use Graphics.DrawString to show the file name, and DrawImage to draw a thumbnail)
4. add click and doubleclick handlers as you see fit.
As an example, this little article[^] uses an owerdrawn ListBox in order to get colored text lines.
|
|
|
|
|
djsproject wrote:
FileInfo[] FileJpg = FileDirectory.GetFiles("*.jpg");
FileInfo[] FileGif = FileDirectory.GetFiles("*.gif");
FileInfo[] FileBmp = FileDirectory.GetFiles("*.bmp");
FileInfo[] FileTif = FileDirectory.GetFiles("*.tif");
FileInfo[] FilePng = FileDirectory.GetFiles("*.png");
foreach (FileInfo File in FileJpg)
{
ImageList.Add(File.Name, File.FullName);
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FileGif)
{
ImageList.Add(File.Name, File.FullName);
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FileGif)
{
ImageList.Add(File.Name, File.FullName);
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FileTif)
{
ImageList.Add(File.Name, File.FullName);
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FilePng)
{
ImageList.Add(File.Name, File.FullName);
checkedListBox1.Items.Add(File.Name);
}
This is WTF. Use at least the following solution please:
string[] extensions = new string[] {"jpg", "gif", "bmp", };
foreach (string extension in extensions)
{
FileInfo[] FileJpg = FileDirectory.GetFiles(string.Format("*.{0}", extension));
foreach (FileInfo File in FileJpg)
{
ImageList.Add(File.Name, File.FullName);
checkedListBox1.Items.Add(File.Name);
}
}
Also, set meaningful names for your controls, please. e.g. change 'button1' to 'buttonAddImage' or sth.
Greetings - Jacek
|
|
|
|
|
hey i want this code of rotating image with all the images that i have selected can somebody tell me how to get it done?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
namespace ImageRotation
{
public partial class Form1 : Form
{
private Image loadedImage;
public Form1()
{
InitializeComponent();
}
private Image RotateImage(Image inputImg, double degreeAngle)
{
PointF[] rotationPoints = { new PointF(0, 0),
new PointF(inputImg.Width, 0),
new PointF(0, inputImg.Height),
new PointF(inputImg.Width, inputImg.Height)};
PointMath.RotatePoints(rotationPoints, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f), degreeAngle);
Rectangle bounds = PointMath.GetBounds(rotationPoints);
Bitmap rotatedBitmap = new Bitmap(bounds.Width, bounds.Height);
using (Graphics g = Graphics.FromImage(rotatedBitmap))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
Matrix m = new Matrix();
m.RotateAt((float)degreeAngle, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f));
m.Translate(-bounds.Left, -bounds.Top, MatrixOrder.Append);
g.Transform = m;
g.DrawImage(inputImg, 0, 0);
}
return (Image)rotatedBitmap;
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
if (loadedImage != null)
pictureBox1.Image = RotateImage(loadedImage, (double)tRotation.Value);
pictureBox1.Refresh();
}
private void btnLoad_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
loadedImage = Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image = loadedImage;
tRotation.Value = 0;
}
catch (Exception)
{
MessageBox.Show("Image invalid.");
}
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.vcskicks.com/");
}
}
public static class PointMath
{
private static double DegreeToRadian(double angle)
{
return Math.PI * angle / 180.0;
}
public static PointF RotatePoint(PointF pnt, double degreeAngle)
{
return RotatePoint(pnt, new PointF(0, 0), degreeAngle);
}
public static PointF RotatePoint(PointF pnt, PointF origin, double degreeAngle)
{
double radAngle = DegreeToRadian(degreeAngle);
PointF newPoint = new PointF();
double deltaX = pnt.X - origin.X;
double deltaY = pnt.Y - origin.Y;
newPoint.X = (float)(origin.X + (Math.Cos(radAngle) * deltaX - Math.Sin(radAngle) * deltaY));
newPoint.Y = (float)(origin.Y + (Math.Sin(radAngle) * deltaX + Math.Cos(radAngle) * deltaY));
return newPoint;
}
public static void RotatePoints(PointF[] pnts, double degreeAngle)
{
for (int i = 0; i < pnts.Length; i++)
{
pnts[i] = RotatePoint(pnts[i], degreeAngle);
}
}
public static void RotatePoints(PointF[] pnts, PointF origin, double degreeAngle)
{
for (int i = 0; i < pnts.Length; i++)
{
pnts[i] = RotatePoint(pnts[i], origin, degreeAngle);
}
}
public static Rectangle GetBounds(PointF[] pnts)
{
RectangleF boundsF = GetBoundsF(pnts);
return new Rectangle((int)Math.Round(boundsF.Left),
(int)Math.Round(boundsF.Top),
(int)Math.Round(boundsF.Width),
(int)Math.Round(boundsF.Height));
}
public static RectangleF GetBoundsF(PointF[] pnts)
{
float left = pnts[0].X;
float right = pnts[0].X;
float top = pnts[0].Y;
float bottom = pnts[0].Y;
for (int i = 1; i < pnts.Length; i++)
{
if (pnts[i].X < left)
left = pnts[i].X;
else if (pnts[i].X > right)
right = pnts[i].X;
if (pnts[i].Y < top)
top = pnts[i].Y;
else if (pnts[i].Y > bottom)
bottom = pnts[i].Y;
}
return new RectangleF(left,
top,
(float)Math.Abs(right - left),
(float)Math.Abs(bottom - top));
}
}
}
this code works for only one image.I want it to run for multiple images.In other words i want it to integrate with the above code.can somebody help..............
|
|
|
|
|
hi guys...i have a problem about string usage..i want to make capital letters of a text in the textbox after space...for example if textbox is entered like that mert efe i want to write like that Mert Efe..to do that i wrote that codes
public string Cevir(string text)
{
string temizlenmis = null;
for (int i = 0; i < text.Length; i++)
{
if ((i == 0) || (i==text.IndexOf(" ")+1))
temizlenmis += char.ToUpper(text[i]);
else
temizlenmis += char.ToLower(text[i]);
}
return temizlenmis;
}
and it works for two words but if i enter third word it doesnt work as i wished...it works like that if i enter three words like mert efe demir and it gives result Mert Efe demir
so what is wrong here ?
|
|
|
|
|
You are searching for the first space every time..
How about (untested)
public string TitleCase(string text)
{
StringBuilder result = new StringBuilder();
bool nextIsCap = true;
for (int i = 0; i < text.Length; i++)
{
if (nextIsCap)
{
result.Append(char.ToUpper(text[i]));
nextIsCap = false;
}
else
result.Append(char.ToLower(text[i]));
if (text[i] == ' ')
nextIsCap = true;
}
return result.ToString();
}
edit: ok that sucked, next try:
(also untested)
public static string ToTitleCase(string text)
{
char[] buffer = text.ToCharArray();
bool nextIsCap = true;
for (int i = 0; i < buffer.Length; i++)
{
if (nextIsCap)
buffer[i] = char.ToUpper(buffer[i]);
else
buffer[i] = char.ToLower(buffer[i]);
nextIsCap = buffer[i] == ' ';
}
return new string(buffer);
}
modified on Thursday, January 7, 2010 8:41 AM
|
|
|
|
|
thanks man
first one gives the result as i wished..but i didnt get the point what was my mistake
|
|
|
|
|
How about the second one, it should give the same result (right?)
Your mistake is that you search for the first space, you could fix it be adding ,i (yes that's all) to the call to IndexOf - but then it will still suck and I really recommend my second version (or the build-in function)
|
|
|
|
|