-
جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
با سلام
شاید سوال تکرای به نظر برسه ، اما من در تاپیکهای سرچ شده جواب سوالم رو نگرفتم!
چطور میشه یک عدد رو به صورت سه رقم سه رقم ، در یکی از سلولهای دیتا گرید ویو ، جدا کرد.
من در فرم که datagirdview قرار دارد در قسمت load فرم پس از پر شدن dataset و پر شدن datagirdview به توسط dataset از کد زیر استفاده می کنم ولی جواب نمی دهد نمیدانم درست است یا خیر
لطفا در این زمینه من را راهنمایی کنید
this.dataGridView1.Columns[3].DefaultCellStyle.Format.Replace("#,#","##");
یا کد زیر
this.dataGridView1.Columns[3].DefaultCellStyle.Format = "N0";
با تشکر فراوان :ناراحت::ناراحت::اشتباه:
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
سلام دوست عزیز چطور چیزی پیدا نکردید عینا سوال شما قبلا پرسیده و به جواب رسید اگر هم جوابتون رو نگرفتید می تونید همون تاپیک ها را ادامه بدید.
اینم جواب.
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
سلام دوست عزیز جناب آقای asefy قبلا من به این تایپ سر زدم ولی جواب نگرفتم و البته لینکی که شما در همان تاپیکی که گذاشته بودید رفتم ولی برای textbox بود و برای textbox که مقادیر پولی می گرفت راهنمایی شدم
اما هنوز برای جدا کردن عددی که در یک سلول از datagridview قرار دارد به جواب نرسیدم
لطفا می شود بیشتر راهنمایی کنید که من از چه دستوری استفاده کنم و باید دستور مورد نظر را در کجا تایپ کنم در ضمن datagridview را خاصیت readonly آنرا true کرده ام
:گریه::گریه:
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
نقل قول:
نوشته شده توسط
mohammad kafiyan
سلام دوست عزیز جناب آقای asefy قبلا من به این تایپ سر زدم ولی جواب نگرفتم و البته لینکی که شما در همان تاپیکی که گذاشته بودید رفتم ولی برای textbox بود و برای textbox که مقادیر پولی می گرفت راهنمایی شدم
اما هنوز برای جدا کردن عددی که در یک سلول از datagridview قرار دارد به جواب نرسیدم
لطفا می شود بیشتر راهنمایی کنید که من از چه دستوری استفاده کنم و باید دستور مورد نظر را در کجا تایپ کنم در ضمن datagridview را خاصیت readonly آنرا true کرده ام
:گریه::گریه:
دوست عزیز من برای این کار از محیط طراحی در Edit Columns گرید ویو ستون مورد نظر رو انتخاب کردم و از قسمت Appearance خاصیت DefultCellStyle رو انتخاب کردم و بعد در کادر باز شده خاصیت format برابر n0 گذاشتم مشکلم حل شد امیدوارم مشکل شما هم حل بشه
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
دوست من روش شما به صورت wizard است و تست کردم جواب نداد چون به صورت دستی در فرم load دارم از طریق dataset ، datagridview پر می کنم من می خواهم به صورت دستی (کد) این کار انجام بشود
نیاز به کد دارم بیشتر راهنماییم کنید :ناراحت::ناراحت:
با تشکر
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
با سلام
روشی که دوستان گفتند یعنی قرار دادن cellStyle به n0 کار میکنه ولی مشکل برنامه شما دوست عزیز اینه که اون ستون از جدول که سلکت زدید آوردید از نوع int یا bigInt نیست بلکه از نوع string هست در این حالت event دیتاگرید ویو را برای cell formatting باید هندل کنید به این شکل :
privatevoid gridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 1)
{
NumberFormatInfo nfi = new NumberFormatInfo();
nfi.CurrencyDecimalDigits = 0;
nfi.CurrencyGroupSeparator = ",";
nfi.CurrencySymbol = "";
Int64 i = 0;
i = Int64.Parse(e.Value.ToString(), NumberStyles.AllowThousands);
e.Value = Int64.Parse(i.ToString(), NumberStyles.AllowThousands).ToString("C", nfi);
}
{
فقط دقت داشته باشید اونجایی که شرط if چک میشه به جای columnIndex==1 شماره ایندکس ستون مورد نظر خودتونو بذارید.
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
سلام جناب آقای اسکندری با تشکر از راهنمایی شما ، بله فیلد قیمت را در database از نوع nvarchar گرفتم و توی برنامه ازنوع string می باشد ، با توجه به توضیحات شما عمل کردم ولی نمی دانم چرا بدشانسم چون به این دو دستور خطا گرفت
NumberFormatInfo nfi = new NumberFormatInfo();
نوع پیغام : The type or namespace name 'NumberFormatInfo' could not be found (are you missing a using directive or an assembly reference?)
به NumberFormatInfo ایراد گرفت و یکی NumberStyles
i = Int64.Parse(e.Value.ToString(), NumberStyles.AllowThousands);
e.Value = Int64.Parse(i.ToString(), NumberStyles.AllowThousands).ToString("C", nfi);
نوع پیغام :The name 'NumberStyles' does not exist in the current context
لطفا باز هم بیشتر مرا راهنمایی کنید
:افسرده::افسرده::افسرده::افس ده::افسرده::ناراحت::ناراحت:: اراحت:
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
کسی نمی دونه این کد چه مشکلی داره ؟
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
dataGridView1.Columns[1].DefaultCellStyle.Format = "#,#";
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
dataGridView1.Columns[1].DefaultCellStyle.Format = "#,#";
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
با سلام،
اگه این کار رو برای واحد پولی میخواین، یعنی اینکه یک سلول قراره مبلغ داشته باشه این جوری میشه:
Dg.Columns[CellName].DefaultCellStyle.Format = "C0";
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
سلام دوستان
اگر عددی دارین و میخواین در GridView به صورت جدا از هم نمایش دهید مثلا 2500 را 2,500 نمایش دهید . در قسمت FotmatStringDialog در GridView قسمت Custom و Customformat را این رشته قرار دهید 0,0,0
http://upload7.ir/images/04121909924652873582.jpg
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
میتونی یک تکست باکس توی فرمت بزاری و بعد خواص Keypress اون رو با یک حرکت حرفه ای روی اون Cell که میخوای اعمال کنی!! اینجوری !
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
TextBox Text = e.Control as TextBox;
if (dataGridView1.CurrentCell.ColumnIndex == dataGridView1.Columns["Column7"].Index)
{
if (Text != null)
{
Text.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
}
}
else
{
if (Text != null)
{
Text.KeyPress -= new KeyPressEventHandler(textBox1_KeyPress);
}
}
}
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
با اين ميتونين برا خونه هاي گريد رويداد textcheng تعريف كنيد
private void dgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
e.Control.TextChanged += dgv_TextCheng;
}
بعد با اين ميتوني سه رقم سه رقم جدا كني
private void dgv_TextCheng;(object sender, EventArgs e)
{
try
{
((TextBox)sender).Text = long.Parse((((TextBox)sender).Text.Replace(",", ""))).ToString("N0");
((TextBox)sender).Select(((TextBox)sender).Text.Le ngth, 0);
}
catch { }
}
حالا اگه خواستس ميتوني اول چك كني ببيني كدوم ستون هست اگه ستون قيمت بود اين كار انجام بشه
-
4 ضمیمه
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
نقل قول:
نوشته شده توسط
mohammad kafiyan
با سلام
شاید سوال تکرای به نظر برسه ، اما من در تاپیکهای سرچ شده جواب سوالم رو نگرفتم!
چطور میشه یک عدد رو به صورت سه رقم سه رقم ، در یکی از سلولهای دیتا گرید ویو ، جدا کرد.
من در فرم که datagirdview قرار دارد در قسمت load فرم پس از پر شدن dataset و پر شدن datagirdview به توسط dataset از کد زیر استفاده می کنم ولی جواب نمی دهد نمیدانم درست است یا خیر
لطفا در این زمینه من را راهنمایی کنید
this.dataGridView1.Columns[3].DefaultCellStyle.Format.Replace("#,#","##");
یا کد زیر
this.dataGridView1.Columns[3].DefaultCellStyle.Format = "N0";
با تشکر فراوان :ناراحت::ناراحت::اشتباه:
دوست عزیز خود دیتاگرید ویو این امکان رو داری و عدد رو به صورت سه رقم اعشار جدا میکنی و احتیاج به کد نویسی نیست.
این هم روش جدا کردن سه رقم اعشار در دیتاگرید ویو
ضمیمه 110103
ضمیمه 110102
ضمیمه 110101
ضمیمه 110100
فقط یک نکته میمونه وقتی دیتاگرید رو ساختید و سلول ها هم ساختید در لحظه ساخت سلول ها سلول مورد نظر رو سه رقم اعشار قرار بدید که کار کنید برای همیشه ولی وقتی دیتاگرید ویو رو به بانک وصل کردید و همه کاراش رو انجام دادید امکانش هستش که عدد رو سه رقم اعشار نکنه که از دیتابیس میخوانه ولی وقتی اول تعیین کنید موقع خواندن اطلاعات از دیتابیس خود برنامه سه رقم جدا میکنه عداد رو اگه برای عدد هستش روی numric برو و مقدار اعشار رو صفر قرار بده یا اگه پول بود روی currency بورو و مقدار رو صفر قرا بده اون موقع ریال هم آخر عدد هم میاری و همچنین یه رقم هم جدا میکنه ولی عدد رو مقدار اعشار و صفر قرار بده.
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
نقل قول:
نوشته شده توسط
hamid_hr
حالا اگه خواستس ميتوني اول چك كني ببيني كدوم ستون هست اگه ستون قيمت بود اين كار انجام بشه
توی Editing Show چجوری میتونیم بدست بیاریم که توی کدوم کالم هستیم ???
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
سلام
dataGridView1.DefaultCellStyle.Format = "N0";
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
نه تو dgv_TextCheng اينو چك ميكني
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
نقل قول:
نوشته شده توسط
hamid_hr
نه تو dgv_TextCheng اينو چك ميكني
یه نمونه میزاری؟
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
رويداد رو كه گفتم چطور اضافه كني
private void dgrid0203detile_TextCheng(object sender, EventArgs e)
{
try
{
if (((DataGridView)sender).SelectedCells[0].ColumnIndex == 1)
{
((TextBox)sender).Text = long.Parse((((TextBox)sender).Text.Replace(",", ""))).ToString("N0");
((TextBox)sender).Select(((TextBox)sender).Text.Le ngth, 0);
}
}
catch { }
}
ايم ميگه اگه ستون اول بود بيا سه رقم سه رقم جدا كن
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
نقل قول:
نوشته شده توسط
hamid_hr
رويداد رو كه گفتم چطور اضافه كني
private void dgrid0203detile_TextCheng(object sender, EventArgs e)
{
try
{
if (((DataGridView)sender).SelectedCells[0].ColumnIndex == 1)
{
((TextBox)sender).Text = long.Parse((((TextBox)sender).Text.Replace(",", ""))).ToString("N0");
((TextBox)sender).Select(((TextBox)sender).Text.Le ngth, 0);
}
}
catch { }
}
ايم ميگه اگه ستون اول بود بيا سه رقم سه رقم جدا كن
این کار نمیکنه !! :اشتباه:
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
نقل قول:
نوشته شده توسط
mohammad kafiyan
سلام جناب آقای اسکندری با تشکر از راهنمایی شما ، بله فیلد قیمت را در database از نوع nvarchar گرفتم و توی برنامه ازنوع string می باشد ، با توجه به توضیحات شما عمل کردم ولی نمی دانم چرا بدشانسم چون به این دو دستور خطا گرفت
NumberFormatInfo nfi = new NumberFormatInfo();
نوع پیغام :
The type or namespace name 'NumberFormatInfo' could not be found (are you missing a using directive or an assembly reference?)
به NumberFormatInfo ایراد گرفت و یکی NumberStyles
i = Int64.Parse(e.Value.ToString(), NumberStyles.AllowThousands);
e.Value = Int64.Parse(i.ToString(), NumberStyles.AllowThousands).ToString("C", nfi);
نوع پیغام :
The name 'NumberStyles' does not exist in the current context
لطفا باز هم بیشتر مرا راهنمایی کنید
:افسرده::افسرده::افسرده::افس ده::افسرده::ناراحت::ناراحت:: اراحت:
using System.Globalization;
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
سلام دوستان
من هم همچین مشکلی دارم،توی برنامه ام فیلد قیمت int هستش و من در لود فرم داده ها رو لود مینکم در جدول(فیلد های گرید ویو ثابت نیست که از فرمت استایلش رو تغییر بدم)حالا وقتی که عدد را مثلا با یک تابع به جای 51000 تبدیل میشه به 51،000 خطا میده که سلول int هست و شما نمی تونیدstring داخلش بریزید.
از طرفی منم نمی تونم نوعش رو تغییر بدم چون خیلی جاها با نوع int اون کار دارم
با تشکر
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
DataGridViewColumn.DefalutCellStyle.Format="N0"
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
سلام دوست عزیز بهترین راه اینه که شما یه ایونت textChange برای cell های گریدت بنویسی و اونجا مدیریتش کنی
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
-
نقل قول: جدا کردن اعداد به صورت سه رقم سه رقم در datagridview
نقل قول:
نوشته شده توسط
hossein_sh2008
سلام دوستان
من هم همچین مشکلی دارم،توی برنامه ام فیلد قیمت int هستش و من در لود فرم داده ها رو لود مینکم در جدول(فیلد های گرید ویو ثابت نیست که از فرمت استایلش رو تغییر بدم)حالا وقتی که عدد را مثلا با یک تابع به جای 51000 تبدیل میشه به 51،000 خطا میده که سلول int هست و شما نمی تونیدstring داخلش بریزید.
از طرفی منم نمی تونم نوعش رو تغییر بدم چون خیلی جاها با نوع int اون کار دارم
با تشکر
دوستان كسي نيست كه با توضيحات بالا كه گفتم يه نمونه كد يا برنامه بذاره