2011/12/05

Get Any Cell Value from a selected row/cell In .NET

Sometimes in your application you need to do a very simple thing like selecting a row in a datagrid to get a cell value, but in .NET's DataGridView will highlight the cell when you click on it and not the row or column.

So why do you have to select a whole row to get a value, or why do you have to select the exact cell i want?
there is a very simple code that accepts any selected cell/row to get your needed cell in that row - check the image:
as you can see I clicked on "Mataderos 2312" cell and got the result "ANTON" which is the value I want, without the need of selecting the whole row or selecting the exact cell needed, just any cell in that row.
code:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim str As String = DataGridView1.Rows(DataGridView1.SelectedCells.Item(0).RowIndex).Cells(0).Value
TextBox1.Text = str
End Sub


code description:
to get the selected item:
DataGridView1.SelectedCells.Item(0).Value
to get it's row index
DataGridView1.SelectedCells.Item(0).RowIndex
to get a cell for it's row
DataGridView1.Rows(DataGridView1.SelectedCells.Item(0).RowIndex).Cells(0).Value

Programming your own Speech Recognition

Speech Recognition
I have a task to develop our own dictionary in windows Speech Recognition (in Windows7), which recogize only our words without having/using the normal (conversation) words that are used in Windows' Dictionary.
and when i was developing that, i did added my own words (as this helpful example), but still the program accepts all kind of words, and i don't want that.
While (hard) searching throught the net, it appeared that this is not possible to have my own dictionary as one said the following:

The shared recogniser which turns on the Windows command recognition grammar. and You can't avoid it, this is disappointing and frustrating. The solution is the second option, creating your own recogniser.
You do not need to turn on the Windows Speech recognition, instead you end up with your own recognition engine, completely independant of the Windows command recogniser.
This MSDN guide is for using WAV -> SR, but most of it applies:
http://msdn.microsoft.com/en-us/library/ms717071%28VS.85%29.aspx
Replace the Stream object wit han spAudio object and you're almost there, here's the Audio Object Code(shortened, no HRESULT checks):
CComPtr pAudioToken;
CComPtr pAudio;

// Try the default
hr = SpGetDefaultTokenFromCategoryId(SPCAT_AUDIOIN, &pAudioToken);


// Connect the Device
hr = pRecognizerEngine->SetInput(pAudioToken, TRUE);

hr = SpCreateDefaultObjectFromCategoryId(SPCAT_AUDIOIN, &pAudio);
hr = pRecognizerEngine->SetInput(pAudio, TRUE);

After that you can continue using the MSDN link above, and will be almost finished, except you need to manually activate the Audio Stram from a microphone / Line-In:
hr = pGrammar->SetGrammarState(SPGS_ENABLED);
hr = pNavGrammar->SetDictationState(SPRS_ACTIVE);
Assuming you are careful in checking the errors, you'll have your own voice recognition, and NO windows commands going off!

Links:
  1. Windows Speech Recognition: How to Benefin from its Advanced Configuration Options
  2. Grammar Format Tags - to create your own grammar (dictionary) as this solitaire example
  3. How to disable windows 7 speech recognition COMMANDS

2011/08/17

Blogger's Template Designer


لطالما كنت أفكر بتحويل هذه المدونة من Blogger إلى Wordpress و أحد الأسباب هو التصاميم البسيطة + قلة/فقر الplugins الموجودة.
لكن بعد زيارتي للوحة التحكم اليوم تغير رأيي حول Blogger إذ أتوقع لها الصمود و ذلك بسبب التحديثات الجديدة مثل الTemplate Designer فهذه تعتبر ميزة جدا قوية له، لن أطيل الشرح أكثر و لكن ادخلوها و اكتشفوها ;)

2011/02/08

لماذا يا كاسبرسكي


اشتريت مؤخرا Wireless USB Adapter و بعدما وصلته على جهازي ذا الويندوز 7 تعرف عليه لكن ظهر أمام الwireless connection أنه Disabled فحاولت تغيير الdriver له عدة مرات، و أيضا جربت Adapter آخر و كل محاولاتي باءت بالفشل!، إلى أن ذهبت إلى خصائص هذا الConnection فوجدت خيار للKaspersky NDIS Filter* فأزلت العلامة منه ثم اشتغل!
إذا كان هذا الخيار يتسبب بعدم تشغيل قطعة الwireless فلماذا هو موجود >_<

*مصدر الصورة و معلومات عنها من هنا

2010/11/21

العلم و التكنولوجيا في العالم العربي

استوقفني هذا الخبر من جريدة القبس ليو الأحد الموافق 21/11/2010
و الذي يتكلم عن العلم و التكنولوجيا في العالم العربي و مدى "فقر" إهتمام الدول فيهما.
و الصراحة في أن هذا الشيء أحزنني قليلا و يجعلني أتأمل نتائج أفضل للدول العربية في المستقبل القريب - قولوا آمين.

لن أتكلم كثيرا في هذا الموضوع، لكن أود أن أذكر أول شي طرأ في بالي عند قراءة هذا الخبر و هو ضعف الترجمة للمصطلحات الحاسوبية و رداءة كتب علم الكمبيوتر/الحاسوب العربية و المعربة، و التي بسببها اتجهت للكتب الانجليزية السهلة و الممتعة منذ أكثر من 3 سنوات.

وصلة لموضوع العلم و التكنولوجيا في العالم العربي

2010/09/27

محاذاة اليمين لمواقع وورد برس الإنجليزية


منذ فترة أردت نقل موضوع عربي إلى موقع luckygg و القائم على وورد برس Wordpress لكن اللغة الأساسية فيه هي الإنجليزية.
فاحتجت لأن أجعل الموضوع العربي يبدأ من اليمين "right-alignment" لكن الخيار لم يكن موجودا (بنقرة واحدة كالMS Word و هنا في blogger)
لذا فيجب تغييره يدويا كالتالي:





أي يجب وضع الخاصيتين style (text-align) و الجهة dir=rtl معا كقالب للمحتوى المراد محاذاته لليمين

2010/08/26

وضع مقرر دراسي جامعي للعبة بورتال

New U.S. College Course Requires Collective  Portal  Playthrough
هذا أحد الأخبار التي أحب أن أسمعها دائما،و هو التشجيع الأكاديمي للجامعات و التي غالبا ما تكون جامعات أجنبية
المهم
هذا الخبر يعني بتدريس نص لعبة Portal كمقرر دراسي في كلية Wabash بجامعة Crawfordsville في إنديانا.
و أعتقد أن السبب في ذلك هو أساس اللعبة التي تمت برمجتها من قبل طلاب مبرمجين في المرحلة الجامعية و أيضا لشعبيتها و حصدها لجوائز عدة.

المميز هنا أن هناك العديد مما يمكن تدريسه في هذه اللعبة (الفكرة و كيفية تحويلها من العقل البشري إلى الكمبيوتر، كتابة النص، كيفية تخيل هذا التحول في اللعبة كعالم ثنائي أو ثلاثي الأبعاد، استخدام محرك اللعبة، الخ)

المصدر:
Gamasutra.com